JuliaPy / JuliaPy/PythonCall.jl

parse gpu array from python to Julia

Offen
#93 7 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Julia
Sterne
1.1k
Forks
86
Ø Merge
1 T. 22 Std.
Gemergte PRs (30 T.)
3

Beschreibung

hello I have cupy cuda array and I want to pass it into julia as is.
CUDA arrays are just list of pointers so it should be possible
from CUDA.jl side I know is possible as I have a comment
"""
for passing data the other way around you can use unsafe_wrap(CuArray, ...) to create a CUDA.jl array from a device pointer you get from Python
"""
still I can not make it work - anybody have some working example?

What I was trying
```
import cupy
import numba
import numpy as np
import torch
import torch.utils.dlpack
from statistics import median
import timeit
from juliacall import Main as jl
# julia.install()
from numba import cuda
jl.seval("using Pkg")
jl.seval("""Pkg.add("CUDA")""")
jl.seval("""Pkg.add("PythonCall")""")
jl.seval("""using CUDA""")
jl.seval("""using PythonCall""")
jl.seval("""CUDA.allowscalar(true)""")
jl.seval("""print(sum(CUDA.ones(3,3,3)))""")# working good
jl.seval("""function bb(arrGold)
# print(CUDA.unsafe_wrap(CuArray{UInt8,3},arrGold, (2,2,2)))
print( pyconvert(CuArray{UInt8} ,arrGold ))
end""")

def print_hi(name):
t1 = torch.cuda.ByteTensor(np.ones((2,2,2)))
c1 = cupy.asarray(t1)

Main.bb(c1)

def forBenchPymia():
numba.cuda.synchronize()
jl.bb(c1)
numba.cuda.synchronize()

num_runs = 1
num_repetions = 1#2
ex_time = timeit.Timer(forBenchPymia).repeat(
repeat=num_repetions,
number=num_runs)
res= median(ex_time)*1000
print("bench")
print(res)

if __name__ == '__main__':
print_hi('PyCharm')

```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Start with the bb entry point and trace how pyconvert handles the CuPy array; compare that path with the mentioned CUDA.unsafe_wrap(CuArray, ...) approach. Use the provided Python and Julia example to reproduce the failure, and consider the work done when a working Python-to-Julia CUDA array example is demonstrated.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
julia, python
Bereich
api
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
20/100

Neue Issues direkt in Ihr Postfach

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