From: Christopher on
Hello everyone,

I'm adding to my own posts because I've run into a new issue. I'm having trouble understanding pointer addition with libpointers, when the pointers point to memory that is in the device space. Here is a modified example:
----------
inHost = single(1 : 10); % Test data
devPtr = libpointer('voidPtr');
% Allocate space for final result
outHostPtr = libpointer('voidPtr', zeros(size(inHost), class(inHost)));
assert(~calllib('libcublas', 'cublasAlloc', length(inHost), 4, devPtr));
assert(~calllib('libcublas', 'cublasSetVector', length(inHost), 4, ...
inHost, 1, devPtr, 1));

% calllib('libcublas', 'cublasSscal', (length(inHost)), 2.0, devPtr, 1);
% Need to call setdatatype() here? What input parameters?
calllib('libcublas', 'cublasSscal', length(inHost) - 1, 2.0, devPtr + 1, 1);

assert(~calllib('libcublas', 'cublasGetError'))
assert(~calllib('libcublas', 'cublasGetVector', length(inHost), 4, ...
devPtr, 1, outHostPtr, 1));
assert(~calllib('libcublas', 'cublasFree', devPtr));
disp(outHostPtr.Value);
---------
My intent was to double all of the elements in my vector except the first one. However, I got the following output result:
"2 4 6 8 10 12 14 16 18 10"
that is, every element except the last one got doubled. So even though I passed "devPtr+1" to the function, it looks like it still started with devPtr. Any ideas on how to fix this example?

--Chris
From: Christopher on
Hi,

It's me again, adding to my own post in case what I have learned is useful to others out there...

I found a way to fix my problem was to create a prototype file and edit it, changing all the parameter types which are pointers to device memory to 'uint64' (with the exception of cublasAlloc, where I used a 'uint64ptr'). I need to be careful to keep track of the element size when doing pointer addition, and I also need to cast my uint64 to double in order to do addition, but at least it works. This seems a bit hackish, so if anyone has a better solution I'd like to hear it.

--Chris