From c63316378101df5fb38e2d3f94a8545f1ff50242 Mon Sep 17 00:00:00 2001 From: Pete Warden Date: Sun, 10 May 2015 19:52:43 +0000 Subject: [PATCH] Fixes for Raspberry Pi 2 --- source/Makefile | 11 +++++++++-- source/src/lib/graph/buffer.cpp | 13 ++++++++++++- source/src/lib/math/matrix_gemm.cpp | 8 ++++++++ source/src/lib/pi/qpu_gemm.cpp | 5 ++++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/source/Makefile b/source/Makefile index 8525bff..afa9168 100644 --- a/source/Makefile +++ b/source/Makefile @@ -5,7 +5,7 @@ CPPFLAGS= .PRECIOUS: %.cdat -LIBCPPFLAGS=-Ofast -I ./src/lib/include -I ./src/lib/graph -I ./src/lib/math -I ./src/lib/third_party -I ./src/lib/utility -I ./src/lib/svm -I ./src/lib/opengl -I ./src/lib -I ./src/include +LIBCPPFLAGS=-Ofast -I ./src/lib/include -I ./src/lib/graph -I ./src/lib/math -I ./src/lib/third_party -I ./src/lib/utility -I ./src/lib/svm -I ./src/lib/opengl -I ./src/lib -I ./src/include -g LIBLDFLAG= LIBLDLIBS= @@ -42,6 +42,13 @@ LIBCPPFLAGS += \ -I./src/lib/pi endif +ifeq ($(TARGET),pi2) +LIBCPPFLAGS += \ +-mcpu=cortex-a7 \ +-mfpu=neon-vfpv4 \ +-mfloat-abi=hard +endif + ifeq ($(GEMM),pigl) LIBCPPFLAGS += \ -I/usr/include \ @@ -63,7 +70,7 @@ ASMOBJS := $(subst .asm,.do,$(ASMSRCS)) LIBOBJS += $(ASMOBJS) endif -TOOLCPPFLAGS := -O3 -I ./src/include +TOOLCPPFLAGS := -O3 -I ./src/include -g TOOLSRCS := $(shell find src/tool -name '*.cpp' -not -name '._*') TOOLOBJS := $(subst .cpp,.o,$(TOOLSRCS)) diff --git a/source/src/lib/graph/buffer.cpp b/source/src/lib/graph/buffer.cpp index 3de05ec..a3e8708 100644 --- a/source/src/lib/graph/buffer.cpp +++ b/source/src/lib/graph/buffer.cpp @@ -31,6 +31,10 @@ #include "mailbox.h" #endif // TARGET_PI +#ifdef USE_EIGEN_GEMM +#include +#endif // USE_EIGEN_GEMM + static void buffer_do_save_to_image_file(Buffer* buffer, const char* filename); Buffer::Buffer(const Dimensions& dims) : @@ -51,6 +55,8 @@ Buffer::Buffer(const Dimensions& dims) : } _gpuMemoryBase = mem_lock(_gpuMemoryHandle); _data = (jpfloat_t*)(mapmem(_gpuMemoryBase + GPU_MEM_MAP, byteCount)); +#elif defined(USE_EIGEN_GEMM) + _data = (jpfloat_t*)(Eigen::internal::aligned_malloc(byteCount)); #else // TARGET_PI _data = (jpfloat_t*)(malloc(byteCount * 1)); #endif // TARGET_PI @@ -114,8 +120,10 @@ Buffer::Buffer(const Dimensions& dims, jpfloat_t min, jpfloat_t max, int bitsPer } _gpuMemoryBase = mem_lock(_gpuMemoryHandle); _quantizedData = (char*)(mapmem(_gpuMemoryBase + GPU_MEM_MAP, byteCount)); +#elif defined(USE_EIGEN_GEMM) + _quantizedData = (void*)(Eigen::internal::aligned_malloc(byteCount)); #else // TARGET_PI - _quantizedData = (void*)(malloc(byteCount * 1)); + _quantizedData = (void*)(malloc(byteCount)); #endif // TARGET_PI _doesOwnData = true; setName("None"); @@ -137,6 +145,9 @@ Buffer::~Buffer() } mem_unlock(_gpuMemoryHandle); mem_free(_gpuMemoryHandle); +#elif defined(USE_EIGEN_GEMM) + Eigen::internal::aligned_free(_data); + Eigen::internal::aligned_free(_quantizedData); #else // TARGET_PI free(_data); free(_quantizedData); diff --git a/source/src/lib/math/matrix_gemm.cpp b/source/src/lib/math/matrix_gemm.cpp index 080b5dd..1ecc5a2 100644 --- a/source/src/lib/math/matrix_gemm.cpp +++ b/source/src/lib/math/matrix_gemm.cpp @@ -391,6 +391,9 @@ void cblas_sgemm_fixed( posix_memalign((void**)(&aSubMatrix), 16, bytesPerSubMatrix); jpfloat_t* cSubMatrix; posix_memalign((void**)(&cSubMatrix), 16, bytesPerSubMatrix); +#elif defined(USE_EIGEN_GEMM) + jpfloat_t* aSubMatrix = (jpfloat_t*)(Eigen::internal::aligned_malloc(bytesPerSubMatrix)); + jpfloat_t* cSubMatrix = (jpfloat_t*)(Eigen::internal::aligned_malloc(bytesPerSubMatrix)); #else // TARGET_PI jpfloat_t* aSubMatrix = (jpfloat_t*)(malloc(bytesPerSubMatrix)); jpfloat_t* cSubMatrix = (jpfloat_t*)(malloc(bytesPerSubMatrix)); @@ -576,8 +579,13 @@ void cblas_sgemm_fixed( #endif // USE_EIGEN_GEMM } +#if defined(USE_EIGEN_GEMM) + Eigen::internal::aligned_free(aSubMatrix); + Eigen::internal::aligned_free(cSubMatrix); +#else // USE_EIGEN_GEMM free(aSubMatrix); free(cSubMatrix); +#endif // USE_EIGEN_GEMM } #endif diff --git a/source/src/lib/pi/qpu_gemm.cpp b/source/src/lib/pi/qpu_gemm.cpp index bbbf0fb..da42cf0 100644 --- a/source/src/lib/pi/qpu_gemm.cpp +++ b/source/src/lib/pi/qpu_gemm.cpp @@ -1,3 +1,4 @@ +#ifdef USE_QPU_GEMM #include #include #include @@ -13,7 +14,7 @@ #define NUM_QPUS (12) #define NUM_MESSAGE_VALUES (2) -//#define DO_LOG_OPERATIONS + extern uint32_t g_gemm_8bitCode[]; extern size_t g_gemm_8bitCodeByteCount; @@ -451,3 +452,5 @@ fprintf(stderr, "\n"); delete outputGPU; delete input; } + +#endif // USE_QPU_GEMM