How to access the elements within the GPU tensor and passing the tensor data from .cpp to .cu

Hi all,

In Pytorch, there is a const Tensor& tensor in a .cpp file, and the tensor is of cudaTensor type. I want to access the elements within the tensor and make a change. I create a .cu file to define a kernel to change the elements within the tensor, but the problem here is that,

I tried to pass the tensor.data_ptr() as the parameter of a function which called to launch the kernel. the structure is like that:
in .cpp
tensor_change((float*)tensor.data_ptr(), number);
in .cu
global void tc(float* po, int number) {
printf("%d\n", number);
printf(“pval = %p\n”, po);
printf(“val = %f\n”, *po);
printf(“val_next = %f\n”, *(po+1)); }

void tensor_change(float* po, int number){
tc<<<1, 1>>>(po, number); }

The result is:
2856768
pval = 0x7faf27200000
val = 0.000000
val_next = 0.000000

My problem is that I am not sure if it is a correct way to use tensor.data_ptr() to pass the value to cuda kernel and use *tensor.data_ptr() to access the element in the tensor. if not, is there other way to access the data?

Any help will be appreciated!
Thanks