Added args and buffer handling, but now clEnqueueNDRangeKernel is failing

with the error invalid command queue. Haven't seen that one before, and
cursory google suggests it's a problem with MBP's. Fun! I'll keep taking
a look, and I'll try it on my windows machine here soon
master
mitchellhansen 8 years ago
parent 0c70c24a52
commit c3902c2f6e

@ -37,7 +37,7 @@ public:
int create_shared_context(); int create_shared_context();
int create_command_queue(); int create_command_queue();
int compile_kernel(std::string kernel_source, bool is_path, std::string kernel_name); int compile_kernel(std::string kernel_source, bool is_path, std::string kernel_name);
int set_kernel_arg(cl_kernel kernel, int index, int size, void* buffer, std::string kernel_name); int set_kernel_arg(std::string kernel_name, int index, std::string buffer_name);
int store_buffer(cl_mem, std::string buffer_name); int store_buffer(cl_mem, std::string buffer_name);
int run_kernel(std::string kernel_name); int run_kernel(std::string kernel_name);
@ -45,6 +45,7 @@ public:
cl_device_id getDeviceID(); cl_device_id getDeviceID();
cl_platform_id getPlatformID(); cl_platform_id getPlatformID();
cl_context getContext(); cl_context getContext();
cl_kernel getKernel(std::string kernel_name);
private: private:

@ -0,0 +1,5 @@
__kernel void min_kern(__global char* in)
{
int a = 10;
printf("%s\n", "this is a test string\n");
}

@ -157,10 +157,11 @@ int CL_Wrapper::create_command_queue(){
int CL_Wrapper::compile_kernel(std::string kernel_source, bool is_path, std::string kernel_name) { int CL_Wrapper::compile_kernel(std::string kernel_source, bool is_path, std::string kernel_name) {
const char* source; const char* source;
std::string tmp;
if (is_path){ if (is_path){
//Load in the kernel, and c stringify it //Load in the kernel, and c stringify it
std::string tmp = read_file(kernel_source); tmp = read_file(kernel_source);
source = tmp.c_str(); source = tmp.c_str();
} else { } else {
source = kernel_source.c_str(); source = kernel_source.c_str();
@ -208,44 +209,51 @@ int CL_Wrapper::compile_kernel(std::string kernel_source, bool is_path, std::str
} }
int CL_Wrapper::set_kernel_arg( int CL_Wrapper::set_kernel_arg(
cl_kernel kernel, std::string kernel_name,
int index, int index,
int size, std::string buffer_name){
void* buffer,
std::string kernel_name){
error = clSetKernelArg(
kernel_map.at(kernel_name),
index,
sizeof(cl_mem),
(void *)&buffer_map.at(buffer_name));
if (assert(error, "clSetKernelArg"))
return -1;
return 0;
}
}; int CL_Wrapper::store_buffer(cl_mem buffer, std::string buffer_name){
int CL_Wrapper::store_buffer(cl_mem, std::string buffer_name){ buffer_map.emplace(std::make_pair(buffer_name, buffer));
buffer_map.emplace(std::make_pair(buffer_name, cl_mem)); }
};
int CL_Wrapper::run_kernel(std::string kernel_name){ int CL_Wrapper::run_kernel(std::string kernel_name){
WORKER_SIZE = 10; const int WORKER_SIZE = 1;
size_t global_work_size[1] = { WORKER_SIZE }; size_t global_work_size[1] = { WORKER_SIZE };
cl_mem kernel = kernel_map.at(kernel_name); cl_kernel kernel = kernel_map.at(kernel_name);
error = clEnqueueNDRangeKernel( error = clEnqueueNDRangeKernel(
command_queue, kernel, command_queue, kernel,
1, NULL, global_work_size, 1, NULL, global_work_size,
NULL, 0, NULL, NULL); NULL, 0, NULL, NULL);
if (assert(error, "clCreateCommandQueue")) if (assert(error, "clEnqueueNDRangeKernel"))
return -1; return -1;
}; }
cl_device_id CL_Wrapper::getDeviceID(){ return device_id; }; cl_device_id CL_Wrapper::getDeviceID(){ return device_id; };
cl_platform_id CL_Wrapper::getPlatformID(){ return platform_id; }; cl_platform_id CL_Wrapper::getPlatformID(){ return platform_id; };
cl_context CL_Wrapper::getContext(){ return context; }; cl_context CL_Wrapper::getContext(){ return context; };
cl_kernel CL_Wrapper::getKernel(std::string kernel_name ){ return kernel_map.at(kernel_name); }
bool CL_Wrapper::assert(int error_code, std::string function_name){ bool CL_Wrapper::assert(int error_code, std::string function_name){

@ -41,6 +41,18 @@ int main(){
c.create_shared_context(); c.create_shared_context();
c.compile_kernel("../kernels/kernel.txt", true, "hello"); c.compile_kernel("../kernels/kernel.txt", true, "hello");
c.compile_kernel("../kernels/minimal_kernel.c", true, "min_kern");
std::string in = "hello!!!!!!!!!!!!!!!!!!!!!";
cl_mem buff = clCreateBuffer(
c.getContext(), CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
sizeof(char) * in.size(), &in, NULL);
c.store_buffer(buff, "buffer_1");
//c.set_kernel_arg("min_kern", 0, "buffer_1");
c.run_kernel("min_kern");
}; };

Loading…
Cancel
Save