Skip to content

Instantly share code, notes, and snippets.

@kevinrobinson
Created December 15, 2015 18:50
Show Gist options
  • Select an option

  • Save kevinrobinson/d8ec92f61db4607a3e93 to your computer and use it in GitHub Desktop.

Select an option

Save kevinrobinson/d8ec92f61db4607a3e93 to your computer and use it in GitHub Desktop.
// Load GPU kernel
gpu::StreamExecutor stream_exec{PlatformKind::kCuda};
gcudacc::kernel::MyKernel my_kernel{&stream_exec};
bool ok = stream_exec.GetKernel(gcudacc::spec::MyKernelSpec(), &my_kernel);
if (!ok) { ... }
// Allocate some CPU memory for the output from the GPU
gpu::DeviceMemory<int> result = stream_exec.AllocateZeroed<int>();
if (result == nullptr) { ... }
// Perform a sequence of GPU operations using the Stream.
int host_result;
gpu::Stream my_stream{&stream_exec};
my_stream
.Init()
.ThenLaunch(ThreadDim{1024}, BlockDim{1}, my_kernel, result)
.ThenMemcpy(&host_result, result, sizeof(host_result))
.BlockHostUntilDone()
if (!my_stream.ok()) { ... }
printf("%d\n", host_result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment