From f70f68fcd465f421b566b199e23e66c1f186b01d Mon Sep 17 00:00:00 2001
From: Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>
Date: Wed, 1 Nov 2017 15:05:13 +0100
Subject: Separate cuda from astra headers further

---
 cuda/2d/astra.cu                   | 41 ++++++++++++++++++++++++++++++++++++++
 cuda/2d/astra.h                    |  9 +++++++++
 cuda/2d/darthelper.cu              | 16 ---------------
 cuda/2d/darthelper.h               |  2 --
 cuda/2d/util.cu                    | 25 -----------------------
 cuda/2d/util.h                     |  4 ----
 python/astra/astra_c.pyx           |  3 +--
 src/CudaDartMaskAlgorithm.cpp      |  1 +
 src/CudaDartSmoothingAlgorithm.cpp |  1 +
 src/CudaDataOperationAlgorithm.cpp |  1 +
 src/CudaRoiSelectAlgorithm.cpp     |  1 +
 11 files changed, 55 insertions(+), 49 deletions(-)

diff --git a/cuda/2d/astra.cu b/cuda/2d/astra.cu
index 2ff9230..c0132b2 100644
--- a/cuda/2d/astra.cu
+++ b/cuda/2d/astra.cu
@@ -986,6 +986,47 @@ bool convertAstraGeometry(const CVolumeGeometry2D* pVolGeom,
 }
 
 
+}
+
+namespace astraCUDA {
+
+
+_AstraExport std::string getCudaDeviceString(int device)
+{
+	char buf[1024];
+	cudaError_t err;
+	if (device == -1) {
+		err = cudaGetDevice(&device);
+		if (err != cudaSuccess) {
+			return "Error getting current GPU index";
+		}
+	}
+
+	cudaDeviceProp prop;
+	err = cudaGetDeviceProperties(&prop, device);
+	if (err != cudaSuccess) {
+		snprintf(buf, 1024, "GPU #%d: Invalid device (%d): %s", device, err, cudaGetErrorString(err));
+		return buf;
+	}
+
+	long mem = prop.totalGlobalMem / (1024*1024);
+	snprintf(buf, 1024, "GPU #%d: %s, with %ldMB", device, prop.name, mem);
+	return buf;
+}
+
+_AstraExport bool setGPUIndex(int iGPUIndex)
+{
+        if (iGPUIndex != -1) {
+                cudaSetDevice(iGPUIndex);
+                cudaError_t err = cudaGetLastError();
+
+                // Ignore errors caused by calling cudaSetDevice multiple times
+                if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess)
+                        return false;
+        }
+
+        return true;
+}
 
 
 }
diff --git a/cuda/2d/astra.h b/cuda/2d/astra.h
index c9e0762..e4cefac 100644
--- a/cuda/2d/astra.h
+++ b/cuda/2d/astra.h
@@ -224,6 +224,15 @@ _AstraExport bool convertAstraGeometry(const CVolumeGeometry2D* pVolGeom,
                     astraCUDA::SFanProjection*& pProjs,
                     float& outputScale);
 
+}
+
+namespace astraCUDA {
+
+// Return string with CUDA device number, name and memory size.
+// Use device == -1 to get info for the current device.
+_AstraExport std::string getCudaDeviceString(int device);
+
+_AstraExport bool setGPUIndex(int index);
 
 }
 #endif
diff --git a/cuda/2d/darthelper.cu b/cuda/2d/darthelper.cu
index 744184e..d4b5220 100644
--- a/cuda/2d/darthelper.cu
+++ b/cuda/2d/darthelper.cu
@@ -356,20 +356,4 @@ void dartSmoothing(float* out, const float* in, float b, unsigned int radius, un
 }
 
 
-
-_AstraExport bool setGPUIndex(int iGPUIndex)
-{
-	if (iGPUIndex != -1) {
-		cudaSetDevice(iGPUIndex);
-		cudaError_t err = cudaGetLastError();
-
-		// Ignore errors caused by calling cudaSetDevice multiple times
-		if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess)
-			return false;
-	}
-
-	return true;
-}
-
-
 }
diff --git a/cuda/2d/darthelper.h b/cuda/2d/darthelper.h
index 9a2837c..67a6a7d 100644
--- a/cuda/2d/darthelper.h
+++ b/cuda/2d/darthelper.h
@@ -36,8 +36,6 @@ namespace astraCUDA {
 	void dartMask(float* out, const float* in, unsigned int conn, unsigned int radius, unsigned int threshold, unsigned int width, unsigned int height);
 	void dartSmoothing(float* out, const float* in, float b, unsigned int radius, unsigned int width, unsigned int height);
 
-	_AstraExport bool setGPUIndex(int index);
-
 }
 
 #endif
diff --git a/cuda/2d/util.cu b/cuda/2d/util.cu
index 9c1bb28..871e139 100644
--- a/cuda/2d/util.cu
+++ b/cuda/2d/util.cu
@@ -274,29 +274,4 @@ void reportCudaError(cudaError_t err)
 }
 
 
-_AstraExport std::string getCudaDeviceString(int device)
-{
-	char buf[1024];
-	cudaError_t err;
-	if (device == -1) {
-		err = cudaGetDevice(&device);
-		if (err != cudaSuccess) {
-			return "Error getting current GPU index";
-		}
-	}
-
-	cudaDeviceProp prop;
-	err = cudaGetDeviceProperties(&prop, device);
-	if (err != cudaSuccess) {
-		snprintf(buf, 1024, "GPU #%d: Invalid device (%d): %s", device, err, cudaGetErrorString(err));
-		return buf;
-	}
-
-	long mem = prop.totalGlobalMem / (1024*1024);
-	snprintf(buf, 1024, "GPU #%d: %s, with %ldMB", device, prop.name, mem);
-	return buf;
-}
-
-
-
 }
diff --git a/cuda/2d/util.h b/cuda/2d/util.h
index 6e36b6e..382d862 100644
--- a/cuda/2d/util.h
+++ b/cuda/2d/util.h
@@ -79,10 +79,6 @@ void reportCudaError(cudaError_t err);
 float dotProduct2D(float* D_data, unsigned int pitch,
                    unsigned int width, unsigned int height);
 
-// Return string with CUDA device number, name and memory size.
-// Use device == -1 to get info for the current device.
-_AstraExport std::string getCudaDeviceString(int device);
-
 }
 
 #endif
diff --git a/python/astra/astra_c.pyx b/python/astra/astra_c.pyx
index f39b0a1..f25fc2a 100644
--- a/python/astra/astra_c.pyx
+++ b/python/astra/astra_c.pyx
@@ -40,9 +40,8 @@ cdef extern from "astra/Globals.h" namespace "astra":
     bool cudaEnabled()
 
 IF HAVE_CUDA==True:
-  cdef extern from "../cuda/2d/darthelper.h" namespace "astraCUDA":
+  cdef extern from "../cuda/2d/astra.h" namespace "astraCUDA":
       bool setGPUIndex(int)
-  cdef extern from "../cuda/2d/util.h" namespace "astraCUDA":
       string getCudaDeviceString(int)
 ELSE:
   def setGPUIndex():
diff --git a/src/CudaDartMaskAlgorithm.cpp b/src/CudaDartMaskAlgorithm.cpp
index 375d565..a2e1ee6 100644
--- a/src/CudaDartMaskAlgorithm.cpp
+++ b/src/CudaDartMaskAlgorithm.cpp
@@ -29,6 +29,7 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
 
 #include "astra/CudaDartMaskAlgorithm.h"
 
+#include "../cuda/2d/astra.h"
 #include "../cuda/2d/darthelper.h"
 #include "../cuda/2d/algo.h"
 
diff --git a/src/CudaDartSmoothingAlgorithm.cpp b/src/CudaDartSmoothingAlgorithm.cpp
index 0759ea0..9e586c0 100644
--- a/src/CudaDartSmoothingAlgorithm.cpp
+++ b/src/CudaDartSmoothingAlgorithm.cpp
@@ -29,6 +29,7 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
 
 #include "astra/CudaDartSmoothingAlgorithm.h"
 
+#include "../cuda/2d/astra.h"
 #include "../cuda/2d/darthelper.h"
 #include "../cuda/2d/algo.h"
 
diff --git a/src/CudaDataOperationAlgorithm.cpp b/src/CudaDataOperationAlgorithm.cpp
index f9466e2..6c6b27c 100644
--- a/src/CudaDataOperationAlgorithm.cpp
+++ b/src/CudaDataOperationAlgorithm.cpp
@@ -31,6 +31,7 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
 
 #include "../cuda/2d/algo.h"
 #include "../cuda/2d/darthelper.h"
+#include "../cuda/2d/astra.h"
 #include "../cuda/2d/arith.h"
 
 #include "astra/AstraObjectManager.h"
diff --git a/src/CudaRoiSelectAlgorithm.cpp b/src/CudaRoiSelectAlgorithm.cpp
index baf8a6f..2b0ba15 100644
--- a/src/CudaRoiSelectAlgorithm.cpp
+++ b/src/CudaRoiSelectAlgorithm.cpp
@@ -29,6 +29,7 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
 
 #include "astra/CudaRoiSelectAlgorithm.h"
 
+#include "../cuda/2d/astra.h"
 #include "../cuda/2d/darthelper.h"
 #include "../cuda/2d/algo.h"
 
-- 
cgit v1.2.3