How to access the GPU pointer which is jumped.

Hello, guys.

I want to access GPU pointer which is jumped.

for example.

void set() {
    err = cudaMalloc((void **)&gpu_attribute_ptr, SIZE * size_valuetype * 32);
    if (err != cudaSuccess) {
        fprintf(stderr, "Failed to allocate device attribute (error code %s)!\n", cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
}

void transferH2D(size_t transfer_size, int index) {
    err = cudaMemcpy(&gpu_attribute_ptr, &RA_ptr, transfer_size * size_valuetype, cudaMemcpyHostToDevice);
    if (err != cudaSuccess) {
	fprintf(stderr, "Failed to copy host to device attribute(error code %s)!\n", cudaGetErrorString(err));
	exit(EXIT_FAILURE);
    }

Is there any problem?

it means can I access the GPU pointer which is jumped using array index.

I use that code but there is garbage value (i.c., all the 0 value);

P.S. the pointer type is char. but calculating the right size.
SIZE consist of data type size * needed numbers
and then casting to using data type in the kernel.
I checked the main memory value, but there is the right value which is set.

CUDA is a subset of C++11. Taking addresses, pointer arithmetic, and indexing off a pointer work exactly the same as they do in ordinary C++.

It is impossible to tell what the problem in your code could be from the snippets you posted. A piece of general advice: If you want people to help you with debugging, you would want to post a minimal, self-contained, buildable, and runnable code that reproduces the problem.

Thank you njuffa.

I thought my problem is an easy thing.

I don’t post my full code due to that reason.

Can I ask the simple question one more?

If I allocate the device pointer to dev_ptr of variable’s name, can I access device pointer any allocate location of dev_ptr?

I thought dev_ptr can access only start address.

Since it is apparently an easy thing, AND you have the full source in front of you, I am confident you can figure this out without further help.

As long as you don’t access out-of-bounds memory (memory that is not part of your allocations), you can do whatever you want. As I stated: In CUDA code, taking addresses, pointer arithmetic, and indexing off a pointer work exactly the same as they do in ordinary C++.

Thank you so much!!

have a good day!