[OpenCL] Use global defined scalar value

This commit is contained in:
Tom Deakin 2016-10-24 13:51:47 +01:00
parent ce5152fefd
commit 0bed614734
2 changed files with 10 additions and 3 deletions

View File

@ -14,7 +14,7 @@ void getDeviceList(void);
std::string kernels{R"CLC( std::string kernels{R"CLC(
constant TYPE scalar = 0.3; constant TYPE scalar = startScalar;
kernel void copy( kernel void copy(
global const TYPE * restrict a, global const TYPE * restrict a,
@ -73,14 +73,17 @@ OCLStream<T>::OCLStream(const unsigned int ARRAY_SIZE, const int device_index)
// Create program // Create program
cl::Program program(context, kernels); cl::Program program(context, kernels);
std::ostringstream args;
args << "-DstartScalar=" << startScalar << " ";
if (sizeof(T) == sizeof(double)) if (sizeof(T) == sizeof(double))
{ {
args << "-DTYPE=double";
// Check device can do double // Check device can do double
if (!device.getInfo<CL_DEVICE_DOUBLE_FP_CONFIG>()) if (!device.getInfo<CL_DEVICE_DOUBLE_FP_CONFIG>())
throw std::runtime_error("Device does not support double precision, please use --float"); throw std::runtime_error("Device does not support double precision, please use --float");
try try
{ {
program.build("-DTYPE=double"); program.build(args.str().c_str());
} }
catch (cl::Error& err) catch (cl::Error& err)
{ {
@ -92,7 +95,10 @@ OCLStream<T>::OCLStream(const unsigned int ARRAY_SIZE, const int device_index)
} }
} }
else if (sizeof(T) == sizeof(float)) else if (sizeof(T) == sizeof(float))
program.build("-DTYPE=float"); {
args << "-DTYPE=float";
program.build(args.str().c_str());
}
// Create kernels // Create kernels
copy_kernel = new cl::KernelFunctor<cl::Buffer, cl::Buffer>(program, "copy"); copy_kernel = new cl::KernelFunctor<cl::Buffer, cl::Buffer>(program, "copy");

View File

@ -8,6 +8,7 @@
#pragma once #pragma once
#include <iostream> #include <iostream>
#include <sstream>
#include <stdexcept> #include <stdexcept>
#define CL_HPP_ENABLE_EXCEPTIONS #define CL_HPP_ENABLE_EXCEPTIONS