From ead415873dca9d7862d291e2d7fbeaa63ecf525f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 5 Sep 2023 08:36:18 +0200 Subject: [PATCH] *_CHECK_THROW: don't shadow `result` --- .editorconfig | 4 ++++ .gitignore | 5 +++-- include/tiny-cuda-nn/common_host.h | 25 ++++++++++++----------- include/tiny-cuda-nn/cutlass_matmul.h | 6 +++--- include/tiny-cuda-nn/optimizers/shampoo.h | 6 +++--- include/tiny-cuda-nn/vec.h | 13 ++++++++++-- 6 files changed, 37 insertions(+), 22 deletions(-) diff --git a/.editorconfig b/.editorconfig index 36bc9449..63576553 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,3 +9,7 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false + +[*.clangd] +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore index 7e062173..0fd2f4fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ .DS_Store *.egg-info -__pycache__ *.o -/*.jpg +__pycache__ build* dist +/.cache /.vscode +/*.jpg diff --git a/include/tiny-cuda-nn/common_host.h b/include/tiny-cuda-nn/common_host.h index 7e2aa9f7..df032d29 100644 --- a/include/tiny-cuda-nn/common_host.h +++ b/include/tiny-cuda-nn/common_host.h @@ -74,10 +74,10 @@ void set_verbose(bool verbose); /// Checks the result of a cuXXXXXX call and throws an error on failure #define CU_CHECK_THROW(x) \ do { \ - CUresult result = x; \ - if (result != CUDA_SUCCESS) { \ + CUresult _result = x; \ + if (_result != CUDA_SUCCESS) { \ const char *msg; \ - cuGetErrorName(result, &msg); \ + cuGetErrorName(_result, &msg); \ throw std::runtime_error{fmt::format(FILE_LINE " " #x " failed: {}", msg)}; \ } \ } while(0) @@ -85,10 +85,10 @@ void set_verbose(bool verbose); /// Checks the result of a cuXXXXXX call and prints an error on failure #define CU_CHECK_PRINT(x) \ do { \ - CUresult result = x; \ - if (result != CUDA_SUCCESS) { \ + CUresult _result = x; \ + if (_result != CUDA_SUCCESS) { \ const char *msg; \ - cuGetErrorName(result, &msg); \ + cuGetErrorName(_result, &msg); \ log_error(FILE_LINE " " #x " failed: {}", msg); \ } \ } while(0) @@ -96,17 +96,18 @@ void set_verbose(bool verbose); /// Checks the result of a cudaXXXXXX call and throws an error on failure #define CUDA_CHECK_THROW(x) \ do { \ - cudaError_t result = x; \ - if (result != cudaSuccess) \ - throw std::runtime_error{fmt::format(FILE_LINE " " #x " failed: {}", cudaGetErrorString(result))}; \ + cudaError_t _result = x; \ + if (_result != cudaSuccess) \ + throw std::runtime_error{fmt::format(FILE_LINE " " #x " failed: {}", cudaGetErrorString(_result))}; \ } while(0) /// Checks the result of a cudaXXXXXX call and prints an error on failure #define CUDA_CHECK_PRINT(x) \ do { \ - cudaError_t result = x; \ - if (result != cudaSuccess) \ - log_error(FILE_LINE " " #x " failed: {}", cudaGetErrorString(result)); \ + cudaError_t _result = x; \ + if (_result != cudaSuccess) \ + log_error(FILE_LINE " " #x " failed: {}", cudaGetErrorString(_result)); \ + } while(0) } while(0) ////////////////////////////// diff --git a/include/tiny-cuda-nn/cutlass_matmul.h b/include/tiny-cuda-nn/cutlass_matmul.h index ff63f19c..da61abc5 100644 --- a/include/tiny-cuda-nn/cutlass_matmul.h +++ b/include/tiny-cuda-nn/cutlass_matmul.h @@ -51,9 +51,9 @@ namespace tcnn { #define CUTLASS_CHECK_THROW(x) \ do { \ - cutlass::Status error = x; \ - if (error != cutlass::Status::kSuccess) \ - throw std::runtime_error(std::string(FILE_LINE " " #x " failed with error ") + cutlassGetStatusString(error)); \ + cutlass::Status _result = x; \ + if (_result != cutlass::Status::kSuccess) \ + throw std::runtime_error(std::string(FILE_LINE " " #x " failed with error ") + cutlassGetStatusString(_result)); \ } while(0) using SmArch = std::conditional_t= 80, diff --git a/include/tiny-cuda-nn/optimizers/shampoo.h b/include/tiny-cuda-nn/optimizers/shampoo.h index 9e5da586..de4b62b3 100644 --- a/include/tiny-cuda-nn/optimizers/shampoo.h +++ b/include/tiny-cuda-nn/optimizers/shampoo.h @@ -63,9 +63,9 @@ inline std::string cublasGetError(cublasStatus_t error) { #define CUBLAS_CHECK_THROW(x) \ do { \ - cublasStatus_t result = x; \ - if (result != CUBLAS_STATUS_SUCCESS) \ - throw std::runtime_error(std::string("CUBLAS Error: " #x " failed with error ") + cublasGetError(result)); \ + cublasStatus_t _result = x; \ + if (_result != CUBLAS_STATUS_SUCCESS) \ + throw std::runtime_error(std::string("CUBLAS Error: " #x " failed with error ") + cublasGetError(_result)); \ } while(0) template diff --git a/include/tiny-cuda-nn/vec.h b/include/tiny-cuda-nn/vec.h index ba791494..383ea726 100644 --- a/include/tiny-cuda-nn/vec.h +++ b/include/tiny-cuda-nn/vec.h @@ -508,6 +508,15 @@ DEF_NON_TEMPLATED_VECTOR_TYPES(u16vec, uint16_t) DEF_NON_TEMPLATED_VECTOR_TYPES(hvec, __half) #endif +#if defined(__CUDACC__) +inline TCNN_HOST_DEVICE float4 to_float4(const vec4& x) { return {x.x, x.y, x.z, x.w}; } +inline TCNN_HOST_DEVICE float3 to_float3(const vec3& x) { return {x.x, x.y, x.z}; } +inline TCNN_HOST_DEVICE float2 to_float2(const vec2& x) { return {x.x, x.y}; } +inline TCNN_HOST_DEVICE vec4 to_vec4(const float4& x) { return {x.x, x.y, x.z, x.w}; } +inline TCNN_HOST_DEVICE vec3 to_vec3(const float3& x) { return {x.x, x.y, x.z}; } +inline TCNN_HOST_DEVICE vec2 to_vec2(const float2& x) { return {x.x, x.y}; } +#endif + template struct tmat { tmat() = default; @@ -1067,14 +1076,14 @@ struct tquat { } else if (m[0][0] > m[1][1] && m[0][0] > m[2][2]) { T S = sqrt((T)1 + m[0][0] - m[1][1] - m[2][2]) * (T)2; // S=4*x w = (m[1][2] - m[2][1]) / S; - x = 0.25 * S; + x = (T)0.25 * S; y = (m[1][0] + m[0][1]) / S; z = (m[2][0] + m[0][2]) / S; } else if (m[1][1] > m[2][2]) { T S = sqrt((T)1 + m[1][1] - m[0][0] - m[2][2]) * (T)2; // S=4*y w = (m[2][0] - m[0][2]) / S; x = (m[1][0] + m[0][1]) / S; - y = 0.25 * S; + y = (T)0.25 * S; z = (m[2][1] + m[1][2]) / S; } else { T S = sqrt((T)1 + m[2][2] - m[0][0] - m[1][1]) * (T)2; // S=4*z