Hello. I’m testing with the __nanosleep function.
I was expecting below code would return 1000ms but I get only about 0.069632ms as result.
My intention was to sleep kernel for about 1 second.
#include <stdio.h>
#define RUNTIME_API_CALL(apiFuncCall) \
do { \
cudaError_t _status = apiFuncCall; \
if (_status != cudaSuccess) { \
fprintf(stderr, "%s:%d: error: function %s failed with error %s.\n", \
__FILE__, __LINE__, #apiFuncCall, cudaGetErrorString(_status)); \
exit(-1); \
} \
} while (0)
__global__ void kernel() {
#if __CUDA_ARCH__ == 860
__nanosleep(1000000000); // ls
#else
printf(">>> __CUDA_ARCH__ != 860\n");
#endif
}
int main() {
cudaEvent_t start, stop;
RUNTIME_API_CALL(cudaEventCreate(&start));
RUNTIME_API_CALL(cudaEventCreate(&stop));
RUNTIME_API_CALL(cudaEventRecord(start));
kernel<<<1, 1>>>();
RUNTIME_API_CALL(cudaEventRecord(stop));
RUNTIME_API_CALL(cudaEventSynchronize(stop));
float duration;
RUNTIME_API_CALL(cudaEventElapsedTime(&duration, start, stop));
printf("Elapsed time: %fms\n", duration);
return 0;
}
I used this command.
nvcc simple.cu -arch=native
How can I make kernel to sleep for 1 second?
RTX 3090
Driver Version: 510.47.03
CUDA Version: 11.6