| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | #include "debug_utility.h" |
| |
|
| | namespace { |
| |
|
| | __global__ void inf_and_nan_checker(const half* tensor, int64_t elem_cnt) { |
| | int64_t nan_num = 0, pos_inf = 0, neg_inf = 0; |
| | for (int64_t i = 0; i < elem_cnt; i++) { |
| | float v = (float)(*(tensor + i)); |
| | if (isnan(v)) { |
| | nan_num += 1; |
| | } |
| | auto is_inf = isinf(v); |
| | if (is_inf) { |
| | if (v > 0) { |
| | pos_inf += 1; |
| | } else { |
| | neg_inf += 1; |
| | } |
| | } |
| | } |
| | if (nan_num > 0 || pos_inf > 0 || neg_inf > 0) { |
| | printf( |
| | "contains NaN: %ld, +INF: %ld, -INF: %ld, total elements: %ld\n", |
| | nan_num, |
| | pos_inf, |
| | neg_inf, |
| | elem_cnt); |
| | } else { |
| | printf("doesn't contain NaN/INF\n"); |
| | } |
| | } |
| |
|
| | __global__ void outputs_checker(const half* tensor, int64_t elem_cnt) { |
| | for (int64_t i = 0; i < elem_cnt; i++) { |
| | float v = (float)(*(tensor + i)); |
| | if (i != 0) { |
| | printf(", "); |
| | } |
| | printf("%f", v); |
| | } |
| | printf("\n"); |
| | } |
| | } |
| |
|
| | namespace ait { |
| | void InvokeInfAndNanChecker( |
| | const half* tensor, |
| | const char* tensor_name, |
| | int64_t elem_cnt, |
| | ait::StreamType stream) { |
| | printf("Tensor (%s) ", tensor_name); |
| | inf_and_nan_checker<<<1, 1, 0, stream>>>(tensor, elem_cnt); |
| | ait::StreamSynchronize(stream); |
| | } |
| |
|
| | void InvokeOutputsChecker( |
| | const half* tensor, |
| | const char* tensor_name, |
| | int64_t elem_cnt, |
| | ait::StreamType stream) { |
| | printf("Tensor (%s) output:\n", tensor_name); |
| | outputs_checker<<<1, 1, 0, stream>>>(tensor, elem_cnt); |
| | ait::StreamSynchronize(stream); |
| | } |
| | } |
| |
|