MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / copy_image

Function copy_image

src/backend/cuda/image.cpp:29–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27
28template<typename T>
29void copy_image(const Array<T> &in, fg_image image) {
30 auto stream = getActiveStream();
31 if (DeviceManager::checkGraphicsInteropCapability()) {
32 auto res = interopManager().getImageResources(image);
33
34 const T *d_X = in.get();
35 size_t bytes = 0;
36 T *d_pixels = NULL;
37 cudaGraphicsMapResources(1, res[0].get(), stream);
38 cudaGraphicsResourceGetMappedPointer((void **)&d_pixels, &bytes,
39 *(res[0].get()));
40 cudaMemcpyAsync(d_pixels, d_X, bytes, cudaMemcpyDeviceToDevice, stream);
41 cudaGraphicsUnmapResources(1, res[0].get(), stream);
42
43 POST_LAUNCH_CHECK();
44 CheckGL("After cuda resource copy");
45 } else {
46 ForgeModule &_ = common::forgePlugin();
47 CheckGL("Begin CUDA fallback-resource copy");
48 unsigned data_size = 0, buffer = 0;
49 FG_CHECK(_.fg_get_image_size(&data_size, image));
50 FG_CHECK(_.fg_get_pixel_buffer(&buffer, image));
51
52 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);
53 glBufferData(GL_PIXEL_UNPACK_BUFFER, data_size, 0, GL_STREAM_DRAW);
54 auto *ptr = static_cast<GLubyte *>(
55 glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY));
56 if (ptr) {
57 CUDA_CHECK(cudaMemcpyAsync(ptr, in.get(), data_size,
58 cudaMemcpyDeviceToHost, stream));
59 CUDA_CHECK(cudaStreamSynchronize(stream));
60 glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
61 }
62 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
63 CheckGL("End CUDA fallback-resource copy");
64 }
65}
66
67#define INSTANTIATE(T) template void copy_image<T>(const Array<T> &, fg_image);
68

Callers

nothing calls this directly

Calls 3

getActiveStreamFunction · 0.85
getImageResourcesMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected