Created
October 8, 2023 22:53
-
-
Save vdivakar/380d44dab1667c46ba56b54e397c2d38 to your computer and use it in GitHub Desktop.
printing from CUDA kernel
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
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