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

Offen
#79 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
25/100
Issue-Typ
Bug
Klarheit
Muss geklärt werden
Aktivitätsstatus
Veraltet
Tech-Stack
cpp, python

Rechercherichtung

Start by reproducing with delete.py after building the add3 extension via setup.py install, since the attached test.zip is the only example. Compare the tensor's strides and contiguity on the Python side with the raw data pointer the kernel receives, and check how the extension's wrapper gets its input. Done means the reporter's question about transposed views is answered, with a reproduction showing why the kernel sees the original memory layout. The linear.cpp link in the issue points to code that is not in the payload.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

  • OS: win10
  • PyTorch version: 1.10
  • How you installed PyTorch (conda, pip, source): pip
  • Python version: 3.9
  • CUDA/cuDNN version: 11.3
  • GPU models and configuration: 1650 geforce PC
  • GCC version (if compiling from source): not sure/.....

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.....

Vorherrschende Sprache
Python
Sterne
1.2k
Forks
250
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus pytorch/extension-cpp

Alle Issues in pytorch/extension-cpp

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.