AnsweredAssumed Answered

How to pass a pointer to structure that contains a value in opencl

Question asked by avinashkrc on Dec 2, 2018
Latest reply on Dec 3, 2018 by dipak

I am trying to work on this code but everytime I gets runtime error "error: field may not be qualified with an address space global uint64_t external;

Here is my data structure in hdr.h:

typedef unsigned long uint64_t;
typedef struct _elem 

  global uint64_t external;
} elem; 

typedef struct _buf

  global elem *kbuf; 

My OpenCL kernel is:

#include "hdr.h"
__kernel void svmtest(global buf *tx) {
  if(get_global_id(0) == 0)
  printf((__constant char *)" %u %s\n", (tx[0].kbuf->external), "test");


My OpenCL C code in brief is as follows:

     parent =(elem*)clSVMAlloc(context, CL_MEM_READ_WRITE|CL_MEM_SVM_FINE_GRAIN_BUFFER , sizeof(elem),0);
     buf *p =(buf*)clSVMAlloc(context, CL_MEM_READ_WRITE|CL_MEM_SVM_FINE_GRAIN_BUFFER , sizeof(buf),0);

     parent->external = 9;

     p[0].kbuf = parent;

     status = clSetKernelArgSVMPointer(kernel, index++, p);
     status= clSetKernelExecInfo(
          sizeof(parent),  &parent

However if I change uint64_ external to uint64_t * external in hdr.h and modify the code accordingly then everything works fine. Can't I pass values in structures, is it must to pass a pointer?