|
|
#pragma once
|
|
|
|
|
|
#include <c10/cuda/CUDAException.h>
|
|
|
#include <c10/macros/Macros.h>
|
|
|
|
|
|
namespace c10::cuda {
|
|
|
|
|
|
#ifdef TORCH_USE_CUDA_DSA
|
|
|
C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wunused-function")
|
|
|
|
|
|
static __device__ void dstrcpy(char* dst, const char* src) {
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
while (*src != '\0' && i++ < C10_CUDA_DSA_MAX_STR_LEN - 1) {
|
|
|
*dst++ = *src++;
|
|
|
}
|
|
|
*dst = '\0';
|
|
|
}
|
|
|
|
|
|
static __device__ void dsa_add_new_assertion_failure(
|
|
|
DeviceAssertionsData* assertions_data,
|
|
|
const char* assertion_msg,
|
|
|
const char* filename,
|
|
|
const char* function_name,
|
|
|
const int line_number,
|
|
|
const uint32_t caller,
|
|
|
const dim3 block_id,
|
|
|
const dim3 thread_id) {
|
|
|
|
|
|
|
|
|
|
|
|
if (!assertions_data) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto nid = atomicAdd(&(assertions_data->assertion_count), 1);
|
|
|
|
|
|
if (nid >= C10_CUDA_DSA_ASSERTION_COUNT) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto& self = assertions_data->assertions[nid];
|
|
|
dstrcpy(self.assertion_msg, assertion_msg);
|
|
|
dstrcpy(self.filename, filename);
|
|
|
dstrcpy(self.function_name, function_name);
|
|
|
self.line_number = line_number;
|
|
|
self.caller = caller;
|
|
|
self.block_id[0] = block_id.x;
|
|
|
self.block_id[1] = block_id.y;
|
|
|
self.block_id[2] = block_id.z;
|
|
|
self.thread_id[0] = thread_id.x;
|
|
|
self.thread_id[1] = thread_id.y;
|
|
|
self.thread_id[2] = thread_id.z;
|
|
|
}
|
|
|
C10_CLANG_DIAGNOSTIC_POP()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define CUDA_KERNEL_ASSERT2(condition) \
|
|
|
do { \
|
|
|
if (C10_UNLIKELY(!(condition))) { \
|
|
|
\
|
|
|
c10::cuda::dsa_add_new_assertion_failure( \
|
|
|
assertions_data, \
|
|
|
C10_STRINGIZE(condition), \
|
|
|
__FILE__, \
|
|
|
__FUNCTION__, \
|
|
|
__LINE__, \
|
|
|
assertion_caller_id, \
|
|
|
blockIdx, \
|
|
|
threadIdx); \
|
|
|
\
|
|
|
\
|
|
|
\
|
|
|
return; \
|
|
|
} \
|
|
|
} while (false)
|
|
|
#else
|
|
|
#define CUDA_KERNEL_ASSERT2(condition) assert(condition)
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|