From 0bed614734effe834d1d3654ebc63345c9fc2458 Mon Sep 17 00:00:00 2001 From: Tom Deakin Date: Mon, 24 Oct 2016 13:51:47 +0100 Subject: [PATCH] [OpenCL] Use global defined scalar value --- OCLStream.cpp | 12 +++++++++--- OCLStream.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/OCLStream.cpp b/OCLStream.cpp index 0ed4b8e..2a1e5ee 100644 --- a/OCLStream.cpp +++ b/OCLStream.cpp @@ -14,7 +14,7 @@ void getDeviceList(void); std::string kernels{R"CLC( - constant TYPE scalar = 0.3; + constant TYPE scalar = startScalar; kernel void copy( global const TYPE * restrict a, @@ -73,14 +73,17 @@ OCLStream::OCLStream(const unsigned int ARRAY_SIZE, const int device_index) // Create program cl::Program program(context, kernels); + std::ostringstream args; + args << "-DstartScalar=" << startScalar << " "; if (sizeof(T) == sizeof(double)) { + args << "-DTYPE=double"; // Check device can do double if (!device.getInfo()) throw std::runtime_error("Device does not support double precision, please use --float"); try { - program.build("-DTYPE=double"); + program.build(args.str().c_str()); } catch (cl::Error& err) { @@ -92,7 +95,10 @@ OCLStream::OCLStream(const unsigned int ARRAY_SIZE, const int device_index) } } else if (sizeof(T) == sizeof(float)) - program.build("-DTYPE=float"); + { + args << "-DTYPE=float"; + program.build(args.str().c_str()); + } // Create kernels copy_kernel = new cl::KernelFunctor(program, "copy"); diff --git a/OCLStream.h b/OCLStream.h index cb48da5..54abaa3 100644 --- a/OCLStream.h +++ b/OCLStream.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #define CL_HPP_ENABLE_EXCEPTIONS