CUDA: How to assert in kernel code?

后端 未结 3 865
臣服心动
臣服心动 2021-01-01 16:45

What is the equivalent technique of an assertion in CUDA kernel code?

There does not seem to be an assert for CUDA kernel code. I w

3条回答
  •  梦谈多话
    2021-01-01 16:58

    I would like to point out that an assert may occur in one thread only, but if you decide to early terminate that thread its absense may cause other bugs (and probably other asserts) happening later; possibly leading to a complete kernel crash and loose of all information on the GPU.

    Also, the answer given at " Using assert within kernel invocation " will work only if the assert is used directly in the __ global__ function and not deeper, somewhere inside __ device__ function.

    My suggestion is, that even an assert fails, you proceed normally with your code, but leave an error message. You can use mapped, pinned memory (you map host RAM memory into GPU address space) to store error codes/messages. That way, even if your kernel crashes and GPU is reset, you are likely to obtain valuable information in that mapped memory. If I am not mistaken, mapped, pinned memory is supported by almost all devices of Compute Capability 1.1 and higher.

提交回复
热议问题