triple-Mu / YOLOv8-TensorRT

YOLOv8 using TensorRT accelerate !
MIT License
1.23k stars 210 forks source link

What is the use of macro CHECK in below code? #197

Closed aravindchakravarti closed 4 months ago

aravindchakravarti commented 4 months ago

Hi, When I look at the tensorRT inference code (csrc/detect/normal/include/yolov8.hpp), in many places CHECK has been called to look for some errors. For example, see below

CHECK(cudaMemcpyAsync(
        this->device_ptrs[0], nchw.ptr<float>(), nchw.total() * nchw.elemSize(), cudaMemcpyHostToDevice, this->stream));

I am not understanding the use of CHECK. What it is doing and is it mandatory to have CHECK?

CHECK expands as below.

#define CHECK(call)                                                                                                    
    do {                                                                                                               
        const cudaError_t error_code = call;                                                                           
        if (error_code != cudaSuccess) {                                                                               
            printf("CUDA Error:\n");                                                                                   
            printf("    File:       %s\n", __FILE__);                                                                  
            printf("    Line:       %d\n", __LINE__);                                                                  
            printf("    Error code: %d\n", error_code);                                                               
            printf("    Error text: %s\n", cudaGetErrorString(error_code));                                            
            exit(1);                                                                                                   
        }                                                                                                              
    } while (0)
triple-Mu commented 4 months ago

Just for checking cuda api return error. Here https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__ERROR.html

aravindchakravarti commented 4 months ago

Hi @triple-Mu Sorry for delayed reply. I was off from work. Thank you for your reply.

So, basically, if I comment out CHECK, meaning if I run the code like below, I will not catch the error which might occur during cudaMemcpyAsync. Is my understanding right?

cudaMemcpyAsync(
        this->device_ptrs[0], nchw.ptr<float>(), nchw.total() * nchw.elemSize(), cudaMemcpyHostToDevice, this->stream);

The reason I am asking is, We are integrating your code in Gstreamer/Deepstream platform. If we run single instance of your code, we are not getting any error in cudaMemcpyAsync line, however, if we run 2 (two) instances of your code parallelly, we get error at cudaMemcpyAsync line. Do you think it is something related to synchronization? or race-condition?

triple-Mu commented 4 months ago

Hi @triple-Mu Sorry for delayed reply. I was off from work. Thank you for your reply.

So, basically, if I comment out CHECK, meaning if I run the code like below, I will not catch the error which might occur during cudaMemcpyAsync. Is my understanding right?

cudaMemcpyAsync(
        this->device_ptrs[0], nchw.ptr<float>(), nchw.total() * nchw.elemSize(), cudaMemcpyHostToDevice, this->stream);

The reason I am asking is, We are integrating your code in Gstreamer/Deepstream platform. If we run single instance of your code, we are not getting any error in cudaMemcpyAsync line, however, if we run 2 (two) instances of your code parallelly, we get error at cudaMemcpyAsync line. Do you think it is something related to synchronization? or race-condition?

Do you mean two process? I think it doesn't matter if you open two process.

aravindchakravarti commented 4 months ago

Thanks @triple-Mu