From b07228a14c7ad6004a06a760081f9c3c723a9209 Mon Sep 17 00:00:00 2001
From: Pietro Incardona <incardon@mpi-cbg.de>
Date: Tue, 15 Jan 2019 22:15:57 +0100
Subject: [PATCH] Small changes

---
 src/CMakeLists.txt        |  1 +
 src/memory/CudaMemory.cu  |  1 -
 src/memory/CudaMemory.cuh |  8 +++++++
 src/util/cuda_util.hpp    | 50 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 src/util/cuda_util.hpp

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2739013..cb9e998 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -16,6 +16,7 @@ if (CUDA_FOUND)
 	target_compile_options(mem PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:-Xcudafe "--display_error_number --diag_suppress=2885 --diag_suppress=2887  --diag_suppress=2888 --diag_suppress=186 --diag_suppress=111" --expt-extended-lambda>)
 endif()
 
+target_include_directories (mem PUBLIC ${CUDA_INCLUDE_DIRS})
 target_include_directories (mem PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
 target_include_directories (mem PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/config)
 target_include_directories (mem PUBLIC ${Boost_INCLUDE_DIRS})
diff --git a/src/memory/CudaMemory.cu b/src/memory/CudaMemory.cu
index 4acab31..ae1f111 100644
--- a/src/memory/CudaMemory.cu
+++ b/src/memory/CudaMemory.cu
@@ -1,6 +1,5 @@
 #include "config.h"
 #include <cstddef>
-#include <cuda_runtime.h>
 #include "CudaMemory.cuh"
 #include "cuda_macro.h"
 #include <cstring>
diff --git a/src/memory/CudaMemory.cuh b/src/memory/CudaMemory.cuh
index 33a1f3e..54b0ff2 100644
--- a/src/memory/CudaMemory.cuh
+++ b/src/memory/CudaMemory.cuh
@@ -40,6 +40,13 @@
 #include "Memleak_check.hpp"
 #endif
 
+#ifdef CUDA_GPU
+
+#include <cuda_runtime.h>
+
+//! Is an array to report general error can happen in CUDA
+static __device__ unsigned char global_cuda_error_array[256];
+
 class CudaMemory : public memory
 {
 	//! Is the host memory synchronized with the GPU memory
@@ -210,4 +217,5 @@ public:
 };
 
 #endif
+#endif
 
diff --git a/src/util/cuda_util.hpp b/src/util/cuda_util.hpp
new file mode 100644
index 0000000..f5805d3
--- /dev/null
+++ b/src/util/cuda_util.hpp
@@ -0,0 +1,50 @@
+/*
+ * cuda_util.hpp
+ *
+ *  Created on: Jun 13, 2018
+ *      Author: i-bird
+ */
+
+#ifndef OPENFPM_DATA_SRC_UTIL_CUDA_UTIL_HPP_
+#define OPENFPM_DATA_SRC_UTIL_CUDA_UTIL_HPP_
+
+#include "config.h"
+#ifdef CUDA_GPU
+#include <cuda_runtime.h>
+#endif
+
+#ifdef CUDA_GPU
+
+	#ifndef __NVCC__
+
+
+	#else
+
+		#ifndef __host__
+		#define __host__
+		#define __device__
+		#endif
+
+		#define CUDA_SAFE(cuda_call) \
+		cuda_call; \
+		{\
+			cudaError_t e = cudaPeekAtLastError();\
+			if (e != cudaSuccess)\
+			{\
+				std::string error = cudaGetErrorString(e);\
+				std::cout << "Cuda Error in: " << __FILE__ << ":" << __LINE__ << " " << error << std::endl;\
+			}\
+		}
+
+	#endif
+#else
+
+#ifndef __host__
+#define __host__
+#define __device__
+#endif
+
+#endif
+
+
+#endif /* OPENFPM_DATA_SRC_UTIL_CUDA_UTIL_HPP_ */
-- 
GitLab