Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using custom structure in opencl

I'm trying to use custom data structure with OpenCL kernel. I defined in my host program a simple structure like :

struct myStruct{
   cl_ulong n_occ;
   cl_ulong start_time;
   cl_ulong end_time;
   cl_ulong exec_time;
   cl_ulong total_time;
   cl_float avg_time;
} myStruct_t;

The equivalent custom data structure definition is also done in my OpenCL kernel.

struct myStruct{
   unsigned long n_occ;
   unsigned long start_time;
   unsigned long end_time;
   unsigned long exec_time;
   unsigned long total_time;
   float avg_time;
} myStruct_t;

The kernel function is the following :

__kernel void process_data( __global myStruct_t* input, __global myStruct_t* output){
    output->start_time = input->start_time;
    output->end_time = input->end_time;
    output->exec_time = input->end_time - input->start_time;
    output->total_time = input->total_time + output->exec_time;
    output->n_occ = input->n_occ + 1;
    output->avg_time = output->total_time / output->n_occ;
}

I use an Nvidia card as GPU device. After the execution of the kernel code, I obtained incorrect results. I don't understand the reason. is there something missing ?

Thank you in advance for your help.

like image 261
semteu Avatar asked Dec 06 '25 10:12

semteu


1 Answers

Have you checked to see if your host struct (C) is packed correctly (also ensure that the OpenCL side is packed correctly and that both report the same size)? It is also probably a good idea to use the same cl_* types in both structs.

like image 176
Ani Avatar answered Dec 08 '25 04:12

Ani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!