Skip to content

Instantly share code, notes, and snippets.

@vdivakar
Created October 8, 2023 22:53
Show Gist options
  • Save vdivakar/380d44dab1667c46ba56b54e397c2d38 to your computer and use it in GitHub Desktop.
Save vdivakar/380d44dab1667c46ba56b54e397c2d38 to your computer and use it in GitHub Desktop.
printing from CUDA kernel
template<typename T>
__global__
void print_buffer(const T* buf, uint num_elements){
for(int i=0; i<num_elements; i++){
printf("%x ", buf[i]); // print hex values
}
printf("\n");
}
template<typename T>
void launch_print_buffer(const T* buf, uint num_elements, cudaStream_t stream){
cudaDeviceSynchronize();
check_cuda_error(cudaGetLastError());
print_buffer<<<1, 1, 0, stream>>>(buf, num_elements);
cudaDeviceSynchronize();
check_cuda_error(cudaGetLastError());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment