Created
December 15, 2015 18:50
-
-
Save kevinrobinson/d8ec92f61db4607a3e93 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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