struct as kernel argument - invalid memory object error

88 views
Skip to first unread message

Samir Kharchi

unread,
Jul 25, 2016, 7:40:17 AM7/25/16
to boost-compute
Hi,

I have a struct I get an "invalid memory object" (-38) error code when I try to set a device vector containing this struct type as kernel argument.


//test.h
struct myTestStruct
{
   
float dhv;
   
float dinvv;      
};

//in global scope
BOOST_COMPUTE_ADAPT_STRUCT
(myTestStruct,myTestStruct,(dhv,dinvv))



//other.cpp
//kernel
const char kernel_cl[] = BOOST_COMPUTE_STRINGIZE_SOURCE(__kernel void test(const __global myTestStruct* input){});

//host code
compute
::vector<myTestStruct> arr(1);
compute
::type_definition<myTestStruct>() + "\n" + kernel_cl;
//then I am building the program and create a corresponding kernel
{...}
kernel
.set_arg(0,arr); //ERRORCODE: -38; invalid memory object





Am I doing anything wrong?

Strangely though, I have another struct that I am adapting in the same way and am passing as a kernel argument inside a vector as well, and for that one I don't get any error. That struct contains float and int members only (about 20).
That vector also contains a lot more entries than just 1 but otherwise I am using the exact same procedure.

I am not sure why it works for one struct but not the other.

Btw. this is the cl program code built (grabbed via debugging) and passed as kernel constructor argument:

typedef struct __attribute__((packed)) {
   
float dhv;
   
float dinvv;
} myTestStruct;

__kernel
void test(const __global myTestStruct* input) { }

Looks fine to me. Any ideas? :-/

Thanks
P.S.: I tried to use boost::compute::float_ as member types too (and some other vector datatypes like boost::compute::float2_) but with the same outcome.

Jakub Szuppe

unread,
Jul 25, 2016, 7:43:42 AM7/25/16
to boost-compute

Hi,

Try: 

kernel.set_arg(0,arr.get_buffer()); 

Kind regards,
Jakub

Jakub Szuppe

unread,
Jul 25, 2016, 7:47:08 AM7/25/16
to boost-compute
And you can also check out "Kernel example" (starting at slide 12) from 

--
You received this message because you are subscribed to the Google Groups "boost-compute" group.
To unsubscribe from this group and stop receiving emails from it, send an email to boost-comput...@googlegroups.com.
To post to this group, send email to boost-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/boost-compute/7452f3c0-35a5-4e30-893b-997fbb81e018%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Samir Kharchi

unread,
Jul 25, 2016, 8:05:21 AM7/25/16
to boost-compute
Sorry, but this also doesn't work for me. :-/ Still am getting the same error message.

Samir Kharchi

unread,
Jul 25, 2016, 8:11:07 AM7/25/16
to boost-compute
Thanks. I am already exactly doing it as in that kernel example (except for kernel arguments passing, which I do one by one).

Jakub Szuppe

unread,
Jul 25, 2016, 8:17:16 AM7/25/16
to boost-compute
We will figure this out :) I'm writing a test now for that.

Samir Kharchi

unread,
Jul 25, 2016, 8:26:30 AM7/25/16
to boost-compute
Jakub. Thanks for all your effort!
But I think there already is a test (https://github.com/boostorg/compute/blob/38ba1c54479869c6ad6d2ea1f828e6d113bc5ab9/test/test_struct.cpp) and in the end it was my fault (again!! argh...).
I forgot to construct the compute vector with the correct context! With that the argument goes through smoothly.

So sorry for the false alarm. I still gotta get used to having these extra data passed into a vector.^^

Anyway, thanks! Your responses made me realise I made that mistake again. :)

Jakub Szuppe

unread,
Jul 25, 2016, 8:30:59 AM7/25/16
to boost-compute
Well, I was just writing to you that I wrote a test and it works for me and you should search some error somewhere
else in your code :) Glad, I could help.
Reply all
Reply to author
Forward
0 new messages