Ich habe einen Artikel über Parallel Seam Carving CPU-GPU gefunden und versuche den Prozess zu verfolgen. CPU-GPU Hybrid and Concurrency method for seam carving. Ich habe bereits die 2 Streams erstellen. Aber ich habe ein Problem, wenn ich versuche, eine asynchrone Kopie der indexMap von Gerät zu Host zu erstellen. Es scheint, als ob die Daten in der indexMap nicht aktualisiert werden. Ich habe immer Nullen Array als die Initialisierung.Cuda Streams mit Pycuda
Hier finden Sie meinen Code.
import pycuda.driver as cuda
import pycuda.autoinit
import pycuda.gpuarray as gpuarray
from pycuda.compiler import SourceModule
import numpy
stream1 = cuda.Stream()
stream2 = cuda.Stream()
energyMap = numpy.random.randn(4,4).astype(numpy.float32)
indexMap = numpy.zeros((3,4)).astype(numpy.float32)
sumMap = numpy.zeros((3,4)).astype(numpy.float32)
energyMap_gpu = gpuarray.to_gpu_async(energyMap, stream = stream2)
indexMap_gpu = cuda.mem_alloc(indexMap.nbytes)
sumMap_gpu = gpuarray.to_gpu_async(sumMap, stream = stream2)
cuda.memcpy_htod(indexMap_gpu, indexMap)
mod = SourceModule("""
__global__ void getIndexMap(float *energyMap, float *indexMap){
some code....
}
__global__ void getSumMap(float *indexMap, float *sumMap){
some code....
}
""")
getIndexMap = mod.get_function("getIndexMap")
getSumMap = mod.get_function("getSumMap")
getIndexMap(energyMap_gpu, indexMap_gpu, block=(4,4,1), stream=stream2)
cuda.memcpy_dtoh_async(indexMap, indexMap_gpu, stream=stream1)
getSumMap(sumMap_gpu, indexMap_gpu, block=(4,4,1), stream=stream2)
print(energyMap)
print(indexMap)
Als ich cuda.memcpy_dtoh_async (indexMap, indexMap_gpu, Strom = stream1) von cuda.memcpy_dtoh (indexMap, indexMap_gpu) ändern bekomme ich das gute Ergebnis.
Soll ich das CudaWaitEvent verwenden? Wenn ja, wie sollte ich es benutzen? Danke!
On-Stack-Überlauf, wenn Sie eine Frage der Form "Warum funktioniert das nicht?" du solltest ein [mcve] bereitstellen. Lesen Sie Punkt 1 [hier] (https://stackoverflow.com/help/on-topic) (<- klicken Sie hier und lesen Sie) –
Problem scheint auf Cross-Posting [hier] (https: // devtalk. nvidia.com/default/topic/1028026/cuda-programming-and-performance/-cuda-streams-with-pycuda/). –
Problem gelöst dank Nvidias Forum. https://devtalk.nvidia.com/default/topic/1028026/cuda-programming-and-performance/-cuda-streams-with-pycuda/ – Hadji