OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1674 Discussions

Problem:Unable to pass structure to a opencl kernel

明_王_
Beginner
253 Views

Unable to pass structure to a opencl kernel?

 

main.h

typedef struct _Point

{

  unsigned int x;

  unsigned int y;

}mPoint;

 

kernel.cl:

#include"main.h"

 

__kernel void Fun(__global struct mPoint* p)

{                               

    unsigned int tid = get_local_id(0);

    p->x=tid;

}

 

The error returned by clBuildProgram():

clBuild failed:-11

Compilation started

1:3:38: warning: declaration of 'struct mPoint' will not be visible outside of t

his function

1:6:3: error: incomplete definition of type 'struct mPoint'

1:3:38: note: forward declaration of 'struct mPoint'

Compilation failed

 

I don't known where is the mistake.

Thanks.

0 Kudos
3 Replies
Alexey_B_Intel1
Employee
253 Views

You should change __kernel void Fun(__global struct mPoint* p) definition.

The best way to fix your issue is to remove 'struct':

__kernel void Fun(__global mPoint* p)

明_王_
Beginner
253 Views

 

I removed 'struct', however, another question emerged:

error: must use 'struct' tag to refer to type 'mPoint'
 __kernel void Fun(__global mPoint* p) 
                                       ^
                                      struct 

Robert_I_Intel
Employee
253 Views

Try to place the content of the main.h header file inside your kernel.cl file: I think what is going on is that when you compile your program, the compiler does not see your header file. Use -I option to the compiler (pass it to clBuildProgram) to point to the right directory where your header file will reside.

Reply