pytorch / extension-cpp

C++ extensions in PyTorch
1.02k stars 214 forks source link

How can I access data in cuda kernel like in pytorch? #79

Open Arsmart123 opened 2 years ago

Arsmart123 commented 2 years ago

I have a tensor a in pytorch, a. And then I transpose it to have a1. But it will not really transpose in memory, but just change the way we read it. And then we pass this pointer to the cuda kernel like is written in the tutorial. Then we access it within the kernel. It is not transposed!!!!! But we enter the pytorch interface and print out the transposed a1, it is correct!

How can we access the tensor within the kernel? We do not know whether it is transposed or not!!!!

Thank you!!! test.zip I have attached a file here. You can reproduce it by unzip it. Then open a python env with pytorch. Also have GPU Then enter: python pytorch/setup.py install You will install the "add3" library. Then run the "delete.py" file within it. You will see how the bug appears like I discribe above!!

Another way to solve it is to understand how nn.linear solve it. How they can access data correctly? I think this is the implementation for nn.linear inside: https://github.com/pytorch/pytorch/blob/4cb534f92ef6f5b2ec99109b0329f93a859ae831/torch/csrc/api/src/nn/modules/linear.cpp But again it links to "torch::nn::linear" And I really can not find the cpp code for it.....