Kev*_*olt 21
CUDA现在具有本机断言功能.使用assert(...)
.如果其参数为零,则将停止内核执行并返回错误.(如果在CUDA调试中,则触发断点.)
确保包含"assert.h".此外,这需要2.x或更高的计算能力,并且在MacOS上不受支持.有关更多详细信息,请参阅"CUDA C编程指南"的B.16节.
编程指南还包括以下示例:
#include <assert.h>
__global__ void testAssert(void)
{
int is_one = 1;
int should_be_one = 0;
// This will have no effect
assert(is_one);
// This will halt kernel execution
assert(should_be_one);
}
int main(int argc, char* argv[])
{
testAssert<<<1,1>>>();
cudaDeviceSynchronize();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5615 次 |
最近记录: |