From c92452f29b8c16e5e8bf63485fd970da5e15fad8 Mon Sep 17 00:00:00 2001
From: Marcel Loose <loose@astron.nl>
Date: Fri, 14 Jun 2013 12:21:15 +0000
Subject: [PATCH] Task #4520: Moved gpu_utils.h one level up (to the generic
 directory). Temporarily added method defaultFlags() and typedef of flags_type
 to this header. Fixed OpenCL code to (temporarily) include OpenCL-specific
 gpu_utils.h header.

---
 .../GPUProc/src/cuda/CudaRuntimeCompiler.cc   | 19 -------
 .../GPUProc/src/cuda/CudaRuntimeCompiler.h    |  5 +-
 RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.cc     | 18 +++++-
 RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.h      | 56 -------------------
 RTCP/Cobalt/GPUProc/src/gpu_utils.h           | 52 ++++++++++++-----
 .../GPUProc/src/opencl/Pipelines/Pipeline.cc  |  2 +-
 .../GPUProc/test/opencl/RTCP_UnitTest.cc      |  2 +-
 RTCP/Cobalt/GPUProc/test/opencl/UnitTest.cc   |  2 +-
 RTCP/Cobalt/GPUProc/test/opencl/tContext.cc   |  2 +-
 .../test/opencl/tPerformanceCounter.cc        |  2 +-
 10 files changed, 62 insertions(+), 98 deletions(-)
 delete mode 100644 RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.h

diff --git a/RTCP/Cobalt/GPUProc/src/cuda/CudaRuntimeCompiler.cc b/RTCP/Cobalt/GPUProc/src/cuda/CudaRuntimeCompiler.cc
index 3737bd27b38..eb534673c1e 100644
--- a/RTCP/Cobalt/GPUProc/src/cuda/CudaRuntimeCompiler.cc
+++ b/RTCP/Cobalt/GPUProc/src/cuda/CudaRuntimeCompiler.cc
@@ -47,25 +47,6 @@ namespace LOFAR
   namespace Cobalt
   {
 
-  // flags
-  typedef std::set<std::string> flags_type;
-
-  // Return the set of default flags for the nvcc compilation of a cuda kernel in Cobalt
-  flags_type defaultFlags()
-  {
-    flags_type flags;
-
-    using boost::format;
-
-    //flags.insert("device-debug");
-    flags.insert("use_fast_math"); // TODO: If this simplifies trig funcs, verify effect on the BPDelayKernel. Ideally, a Kernel specifies when to enable build flags.
-
-    // gpu-architecture and -Ipath are set by createPTX()
-
-    return flags;    
-  };
-
-
   // Performs a 'system' call of nvcc. Return the stdout of the command
   // on error no stdout is created and an exception is thrown
   std::string runNVCC(const std::string &cmd)
diff --git a/RTCP/Cobalt/GPUProc/src/cuda/CudaRuntimeCompiler.h b/RTCP/Cobalt/GPUProc/src/cuda/CudaRuntimeCompiler.h
index f8e816417a1..41741f617e2 100644
--- a/RTCP/Cobalt/GPUProc/src/cuda/CudaRuntimeCompiler.h
+++ b/RTCP/Cobalt/GPUProc/src/cuda/CudaRuntimeCompiler.h
@@ -31,6 +31,7 @@
 
 #include <CoInterface/Parset.h>
 #include <GPUProc/Kernels/CompileDefinitions.h>
+#include <GPUProc/gpu_utils.h>
 #include "gpu_incl.h"
 
 // Collection of functions needed for runtime compilation of a kernel supplied 
@@ -40,8 +41,8 @@ namespace LOFAR
   namespace Cobalt
   {
 
-  // flags
-  typedef std::set<std::string> flags_type;
+  // // flags
+  // typedef std::set<std::string> flags_type;
 
   // Return the set of default flags for the nvcc compilation of a cuda kernel in Cobalt
   flags_type defaultFlags();
diff --git a/RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.cc b/RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.cc
index 3309cc72128..086e4dbee4f 100644
--- a/RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.cc
+++ b/RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.cc
@@ -20,7 +20,7 @@
 
 #include <lofar_config.h>
 
-#include "gpu_utils.h"
+#include <GPUProc/gpu_utils.h>
 
 #include <cstdlib>
 #include <sys/types.h>
@@ -51,6 +51,22 @@ namespace LOFAR
     using namespace std;
     using boost::format;
 
+    flags_type defaultFlags()
+    {
+      flags_type flags;
+
+      using boost::format;
+
+      //flags.insert("device-debug");
+
+      // TODO: If this simplifies trig funcs, verify effect on the
+      // BPDelayKernel. Ideally, a Kernel specifies when to enable build flags.
+      flags.insert("use_fast_math");
+
+      return flags;    
+    };
+
+
     namespace {
 
       // Return the highest compute target supported by the given device
diff --git a/RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.h b/RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.h
deleted file mode 100644
index 62526a01c20..00000000000
--- a/RTCP/Cobalt/GPUProc/src/cuda/gpu_utils.h
+++ /dev/null
@@ -1,56 +0,0 @@
-//# gpu_utils.h
-//# Copyright (C) 2013  ASTRON (Netherlands Institute for Radio Astronomy)
-//# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
-//#
-//# This file is part of the LOFAR software suite.
-//# The LOFAR software suite is free software: you can redistribute it and/or
-//# modify it under the terms of the GNU General Public License as published
-//# by the Free Software Foundation, either version 3 of the License, or
-//# (at your option) any later version.
-//#
-//# The LOFAR software suite is distributed in the hope that it will be useful,
-//# but WITHOUT ANY WARRANTY; without even the implied warranty of
-//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//# GNU General Public License for more details.
-//#
-//# You should have received a copy of the GNU General Public License along
-//# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
-//#
-//# $Id$
-
-#ifndef LOFAR_GPUPROC_CUDA_GPU_UTILS_H
-#define LOFAR_GPUPROC_CUDA_GPU_UTILS_H
-
-#include <string>
-#include <vector>
-
-#include <CoInterface/Parset.h>
-#include "gpu_wrapper.h"
-#include "CudaRuntimeCompiler.h"
-
-namespace LOFAR
-{
-  namespace Cobalt
-  {
-    class CompileDefinitions;
-    /*
-     * If no devices are given, the program is compiled for the latest
-     * architecture.
-     *
-     * srcFilename cannot be an absolute path.
-     */
-    std::string createPTX( const std::vector<gpu::Device> &devices,
-                           const std::string &srcFilename, 
-                           flags_type &flags,
-                           const CompileDefinitions &definitions );
-    /*
-     * Create a Module from a PTX (string).
-     */
-    gpu::Module createModule( const gpu::Context &context,
-                              const std::string &srcFilename, 
-                              const std::string &ptx );
-  }
-}
-
-#endif
-
diff --git a/RTCP/Cobalt/GPUProc/src/gpu_utils.h b/RTCP/Cobalt/GPUProc/src/gpu_utils.h
index 48ba1372d7f..45bd1fae4c2 100644
--- a/RTCP/Cobalt/GPUProc/src/gpu_utils.h
+++ b/RTCP/Cobalt/GPUProc/src/gpu_utils.h
@@ -1,5 +1,4 @@
 //# gpu_utils.h
-//#
 //# Copyright (C) 2013  ASTRON (Netherlands Institute for Radio Astronomy)
 //# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands
 //#
@@ -19,23 +18,46 @@
 //#
 //# $Id$
 
-// \file
-// Support functions for GPU device selection, context, program management.
+#ifndef LOFAR_GPUPROC_CUDA_GPU_UTILS_H
+#define LOFAR_GPUPROC_CUDA_GPU_UTILS_H
 
-#ifndef LOFAR_GPU_UTILS_H
-#define LOFAR_GPU_UTILS_H
+#include <string>
+#include <vector>
 
-#if defined (USE_CUDA) && defined (USE_OPENCL)
-# error "Either CUDA or OpenCL must be enabled, not both"
-#endif
+#include <CoInterface/Parset.h>
+#include "gpu_wrapper.h"
+// #include "CudaRuntimeCompiler.h"
 
-#if defined (USE_CUDA)
-# include "cuda/gpu_utils.h"
-#elif defined (USE_OPENCL)
-# include "opencl/gpu_utils.h"
-#else
-# error "Either CUDA or OpenCL must be enabled, not neither"
-#endif
+namespace LOFAR
+{
+  namespace Cobalt
+  {
+    // flags
+    typedef std::set<std::string> flags_type;
+
+    // Return default flags to be used for kernel compilation. The
+    // implementation of this method is CUDA/OpenCL specific.
+    flags_type defaultFlags();
+
+    class CompileDefinitions;
+    /*
+     * If no devices are given, the program is compiled for the latest
+     * architecture.
+     *
+     * srcFilename cannot be an absolute path.
+     */
+    std::string createPTX( const std::vector<gpu::Device> &devices,
+                           const std::string &srcFilename, 
+                           flags_type &flags,
+                           const CompileDefinitions &definitions );
+    /*
+     * Create a Module from a PTX (string).
+     */
+    gpu::Module createModule( const gpu::Context &context,
+                              const std::string &srcFilename, 
+                              const std::string &ptx );
+  }
+}
 
 #endif
 
diff --git a/RTCP/Cobalt/GPUProc/src/opencl/Pipelines/Pipeline.cc b/RTCP/Cobalt/GPUProc/src/opencl/Pipelines/Pipeline.cc
index dadb9d7483d..fd645d27b43 100644
--- a/RTCP/Cobalt/GPUProc/src/opencl/Pipelines/Pipeline.cc
+++ b/RTCP/Cobalt/GPUProc/src/opencl/Pipelines/Pipeline.cc
@@ -25,7 +25,7 @@
 #include <Common/LofarLogger.h>
 #include <Common/lofar_iomanip.h>
 
-#include <GPUProc/gpu_utils.h>
+#include <GPUProc/opencl/gpu_utils.h>
 
 namespace LOFAR
 {
diff --git a/RTCP/Cobalt/GPUProc/test/opencl/RTCP_UnitTest.cc b/RTCP/Cobalt/GPUProc/test/opencl/RTCP_UnitTest.cc
index 22f447f5300..cb495269257 100644
--- a/RTCP/Cobalt/GPUProc/test/opencl/RTCP_UnitTest.cc
+++ b/RTCP/Cobalt/GPUProc/test/opencl/RTCP_UnitTest.cc
@@ -29,7 +29,7 @@
 
 #include <GPUProc/global_defines.h>
 #include <GPUProc/MultiDimArrayHostBuffer.h>
-#include <GPUProc/gpu_utils.h>
+#include <GPUProc/opencl/gpu_utils.h>
 
 #include <UnitTest.h>
 #include "Kernels/IncoherentStokesTest.h"
diff --git a/RTCP/Cobalt/GPUProc/test/opencl/UnitTest.cc b/RTCP/Cobalt/GPUProc/test/opencl/UnitTest.cc
index bc0282ea911..97b7c8fa6a4 100644
--- a/RTCP/Cobalt/GPUProc/test/opencl/UnitTest.cc
+++ b/RTCP/Cobalt/GPUProc/test/opencl/UnitTest.cc
@@ -27,7 +27,7 @@
 #include <cmath>
 
 #include <GPUProc/global_defines.h>
-#include <GPUProc/gpu_utils.h>
+#include <GPUProc/opencl/gpu_utils.h>
 
 namespace LOFAR
 {
diff --git a/RTCP/Cobalt/GPUProc/test/opencl/tContext.cc b/RTCP/Cobalt/GPUProc/test/opencl/tContext.cc
index 6fd887a480a..2835affc51a 100644
--- a/RTCP/Cobalt/GPUProc/test/opencl/tContext.cc
+++ b/RTCP/Cobalt/GPUProc/test/opencl/tContext.cc
@@ -23,7 +23,7 @@
 #include <vector>
 #include <Common/LofarLogger.h>
 
-#include <GPUProc/gpu_utils.h>
+#include <GPUProc/opencl/gpu_utils.h>
 
 using namespace LOFAR;
 using namespace Cobalt;
diff --git a/RTCP/Cobalt/GPUProc/test/opencl/tPerformanceCounter.cc b/RTCP/Cobalt/GPUProc/test/opencl/tPerformanceCounter.cc
index 9fcbeeca992..684ff29b4b1 100644
--- a/RTCP/Cobalt/GPUProc/test/opencl/tPerformanceCounter.cc
+++ b/RTCP/Cobalt/GPUProc/test/opencl/tPerformanceCounter.cc
@@ -24,7 +24,7 @@
 #include <Common/LofarLogger.h>
 
 #include <GPUProc/MultiDimArrayHostBuffer.h>
-#include <GPUProc/gpu_utils.h>
+#include <GPUProc/opencl/gpu_utils.h>
 #include <GPUProc/PerformanceCounter.h>
 
 using namespace LOFAR;
-- 
GitLab