From 261bb9ca25c362f818a1f52f8d9ba95fdb96698f Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Thu, 6 Jan 2022 16:06:21 -0800 Subject: [PATCH 1/7] move string and exception out of headers --- CMakeLists.txt | 1 + include/camp/defines.hpp | 38 ++++----------------------------- include/camp/resource/cuda.hpp | 6 ++---- include/camp/resource/event.hpp | 3 +-- include/camp/resource/hip.hpp | 6 ++---- 5 files changed, 10 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 35b72c1..7dc26f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,7 @@ configure_file(${PROJECT_SOURCE_DIR}/include/camp/config.in.hpp blt_add_library ( NAME camp HEADERS ${camp_headers} + SOURCES ./src/errors.cpp DEPENDS_ON ${camp_depends} ) target_include_directories (camp INTERFACE diff --git a/include/camp/defines.hpp b/include/camp/defines.hpp index 4792d0a..78822ce 100644 --- a/include/camp/defines.hpp +++ b/include/camp/defines.hpp @@ -13,8 +13,6 @@ For details about use and distribution, please read LICENSE and NOTICE from #include #include -#include -#include #include @@ -178,6 +176,8 @@ using nullptr_t = decltype(nullptr); using type = typename X::type; \ } +/// Throw a runtime_error, avoid including exception everywhere +void throw_re(const char *s); #ifdef CAMP_ENABLE_CUDA @@ -186,22 +186,7 @@ using nullptr_t = decltype(nullptr); inline cudaError_t cudaAssert(cudaError_t code, const char *call, const char *file, - int line) -{ - if (code != cudaSuccess && code != cudaErrorNotReady) { - std::string msg; - msg += "campCudaErrchk("; - msg += call; - msg += ") "; - msg += cudaGetErrorString(code); - msg += " "; - msg += file; - msg += ":"; - msg += std::to_string(line); - throw std::runtime_error(msg); - } - return code; -} + int line); #endif //#ifdef CAMP_ENABLE_CUDA @@ -213,22 +198,7 @@ inline cudaError_t cudaAssert(cudaError_t code, inline hipError_t hipAssert(hipError_t code, const char *call, const char *file, - int line) -{ - if (code != hipSuccess && code != hipErrorNotReady) { - std::string msg; - msg += "campHipErrchk("; - msg += call; - msg += ") "; - msg += hipGetErrorString(code); - msg += " "; - msg += file; - msg += ":"; - msg += std::to_string(line); - throw std::runtime_error(msg); - } - return code; -} + int line); #endif //#ifdef CAMP_ENABLE_HIP diff --git a/include/camp/resource/cuda.hpp b/include/camp/resource/cuda.hpp index 974a6f2..b612240 100644 --- a/include/camp/resource/cuda.hpp +++ b/include/camp/resource/cuda.hpp @@ -19,8 +19,6 @@ For details about use and distribution, please read LICENSE and NOTICE from #include -#include - namespace camp { namespace resources @@ -125,7 +123,7 @@ namespace resources return MemoryAccess::Managed; } } - throw std::runtime_error("invalid pointer detected"); + ::camp::throw_re("invalid pointer detected"); } public: Cuda(int group = -1, int dev = 0) @@ -232,7 +230,7 @@ namespace resources campCudaErrchk(cudaFree(p)); break; case MemoryAccess::Unknown: - throw std::runtime_error("Unknown memory access type, cannot free"); + ::camp::throw_re("Unknown memory access type, cannot free"); } } void memcpy(void *dst, const void *src, size_t size) diff --git a/include/camp/resource/event.hpp b/include/camp/resource/event.hpp index da03e48..447709e 100644 --- a/include/camp/resource/event.hpp +++ b/include/camp/resource/event.hpp @@ -12,7 +12,6 @@ For details about use and distribution, please read LICENSE and NOTICE from #define __CAMP_EVENT_HPP #include -#include #include namespace camp @@ -60,7 +59,7 @@ namespace resources { auto result = dynamic_cast *>(m_value.get()); if (result == nullptr) { - throw std::runtime_error("Incompatible Event type get cast."); + ::camp::throw_re("Incompatible Event type get cast."); } return *result->get(); } diff --git a/include/camp/resource/hip.hpp b/include/camp/resource/hip.hpp index 8a7dc8e..8d3dfd8 100644 --- a/include/camp/resource/hip.hpp +++ b/include/camp/resource/hip.hpp @@ -17,8 +17,6 @@ For details about use and distribution, please read LICENSE and NOTICE from #ifdef CAMP_ENABLE_HIP #include -#include - namespace camp { namespace resources @@ -122,7 +120,7 @@ namespace resources return MemoryAccess::Unknown; } } - throw std::runtime_error("invalid pointer detected"); + ::camp::throw_re("invalid pointer detected"); } public: @@ -229,7 +227,7 @@ namespace resources campHipErrchk(hipFree(p)); break; case MemoryAccess::Unknown: - throw std::runtime_error("Unknown memory access type, cannot free"); + ::camp::throw_re("Unknown memory access type, cannot free"); break; } } From 94f73b23a9d5025a90f7d9694654be6ae8782f7d Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Thu, 6 Jan 2022 16:08:57 -0800 Subject: [PATCH 2/7] helps to include the source --- src/errors.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/errors.cpp diff --git a/src/errors.cpp b/src/errors.cpp new file mode 100644 index 0000000..4f5f6cd --- /dev/null +++ b/src/errors.cpp @@ -0,0 +1,74 @@ +/* +Copyright (c) 2016-18, Lawrence Livermore National Security, LLC. +Produced at the Lawrence Livermore National Laboratory +Maintained by Tom Scogland +CODE-756261, All rights reserved. +This file is part of camp. +For details about use and distribution, please read LICENSE and NOTICE from +http://github.com/llnl/camp +*/ + +#include +#include +#include +#include + + +namespace camp +{ + +void throw_re(const char *s) { throw std::runtime_error(s); } + +#ifdef CAMP_ENABLE_CUDA + +#define campCudaErrchk(ans) ::camp::cudaAssert((ans), #ans, __FILE__, __LINE__) + +inline cudaError_t cudaAssert(cudaError_t code, + const char *call, + const char *file, + int line) +{ + if (code != cudaSuccess && code != cudaErrorNotReady) { + std::string msg; + msg += "campCudaErrchk("; + msg += call; + msg += ") "; + msg += cudaGetErrorString(code); + msg += " "; + msg += file; + msg += ":"; + msg += std::to_string(line); + throw std::runtime_error(msg); + } + return code; +} + +#endif //#ifdef CAMP_ENABLE_CUDA + +#ifdef CAMP_ENABLE_HIP + +#define campHipErrchk(ans) ::camp::hipAssert((ans), #ans, __FILE__, __LINE__) + +inline hipError_t hipAssert(hipError_t code, + const char *call, + const char *file, + int line) +{ + if (code != hipSuccess && code != hipErrorNotReady) { + std::string msg; + msg += "campHipErrchk("; + msg += call; + msg += ") "; + msg += hipGetErrorString(code); + msg += " "; + msg += file; + msg += ":"; + msg += std::to_string(line); + throw std::runtime_error(msg); + } + return code; +} + +#endif //#ifdef CAMP_ENABLE_HIP + +} // namespace camp From f942384d8bfa1df5cd61490b1f0c4b0ccac73cd8 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Thu, 6 Jan 2022 16:27:04 -0800 Subject: [PATCH 3/7] remove unnecessary includes --- CMakeLists.txt | 2 +- include/camp/camp.hpp | 1 - include/camp/helpers.hpp | 1 - include/camp/number.hpp | 1 - include/camp/resource/sycl.hpp | 1 + include/camp/tuple.hpp | 2 +- 6 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7dc26f8..1ee3e08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,7 +106,7 @@ blt_add_library ( SOURCES ./src/errors.cpp DEPENDS_ON ${camp_depends} ) -target_include_directories (camp INTERFACE +target_include_directories (camp PUBLIC $ $ $ diff --git a/include/camp/camp.hpp b/include/camp/camp.hpp index e345ffd..d67482d 100644 --- a/include/camp/camp.hpp +++ b/include/camp/camp.hpp @@ -11,7 +11,6 @@ For details about use and distribution, please read LICENSE and NOTICE from #ifndef __CAMP_HPP #define __CAMP_HPP -#include #include #include diff --git a/include/camp/helpers.hpp b/include/camp/helpers.hpp index bcacd4b..192dc7b 100644 --- a/include/camp/helpers.hpp +++ b/include/camp/helpers.hpp @@ -12,7 +12,6 @@ For details about use and distribution, please read LICENSE and NOTICE from #define CAMP_HELPERS_HPP #include -#include #include #include "camp/defines.hpp" diff --git a/include/camp/number.hpp b/include/camp/number.hpp index 0ec25d8..9fab549 100644 --- a/include/camp/number.hpp +++ b/include/camp/number.hpp @@ -17,7 +17,6 @@ For details about use and distribution, please read LICENSE and NOTICE from #include "camp/defines.hpp" -#include #include namespace camp diff --git a/include/camp/resource/sycl.hpp b/include/camp/resource/sycl.hpp index 8667c30..6823d49 100644 --- a/include/camp/resource/sycl.hpp +++ b/include/camp/resource/sycl.hpp @@ -18,6 +18,7 @@ For details about use and distribution, please read LICENSE and NOTICE from #ifdef CAMP_ENABLE_SYCL #include #include +#include using namespace cl; namespace camp diff --git a/include/camp/tuple.hpp b/include/camp/tuple.hpp index d1b8f0f..524e59f 100644 --- a/include/camp/tuple.hpp +++ b/include/camp/tuple.hpp @@ -17,7 +17,7 @@ For details about use and distribution, please read LICENSE and NOTICE from * \brief Exceptionally basic tuple for host-device support */ -#include +#include #include #include "camp/concepts.hpp" From 13b5c35391c7b8456aaaf873adfd4d61852f4a0d Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Thu, 6 Jan 2022 16:31:23 -0800 Subject: [PATCH 4/7] make assertion functions non-inline --- include/camp/defines.hpp | 4 ++-- include/camp/resource/hip.hpp | 2 ++ src/errors.cpp | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/camp/defines.hpp b/include/camp/defines.hpp index 78822ce..45c2130 100644 --- a/include/camp/defines.hpp +++ b/include/camp/defines.hpp @@ -183,7 +183,7 @@ void throw_re(const char *s); #define campCudaErrchk(ans) ::camp::cudaAssert((ans), #ans, __FILE__, __LINE__) -inline cudaError_t cudaAssert(cudaError_t code, +cudaError_t cudaAssert(cudaError_t code, const char *call, const char *file, int line); @@ -195,7 +195,7 @@ inline cudaError_t cudaAssert(cudaError_t code, #define campHipErrchk(ans) ::camp::hipAssert((ans), #ans, __FILE__, __LINE__) -inline hipError_t hipAssert(hipError_t code, +hipError_t hipAssert(hipError_t code, const char *call, const char *file, int line); diff --git a/include/camp/resource/hip.hpp b/include/camp/resource/hip.hpp index 8d3dfd8..c55328a 100644 --- a/include/camp/resource/hip.hpp +++ b/include/camp/resource/hip.hpp @@ -121,6 +121,8 @@ namespace resources } } ::camp::throw_re("invalid pointer detected"); + // unreachable + return MemoryAccess::Unknown; } public: diff --git a/src/errors.cpp b/src/errors.cpp index 4f5f6cd..bb82a09 100644 --- a/src/errors.cpp +++ b/src/errors.cpp @@ -23,7 +23,7 @@ void throw_re(const char *s) { throw std::runtime_error(s); } #define campCudaErrchk(ans) ::camp::cudaAssert((ans), #ans, __FILE__, __LINE__) -inline cudaError_t cudaAssert(cudaError_t code, +cudaError_t cudaAssert(cudaError_t code, const char *call, const char *file, int line) @@ -49,7 +49,7 @@ inline cudaError_t cudaAssert(cudaError_t code, #define campHipErrchk(ans) ::camp::hipAssert((ans), #ans, __FILE__, __LINE__) -inline hipError_t hipAssert(hipError_t code, +hipError_t hipAssert(hipError_t code, const char *call, const char *file, int line) From e75bd4e1287eb977e4c77d6d4f46b0a816c5b309 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Fri, 7 Jan 2022 09:20:26 -0800 Subject: [PATCH 5/7] build in parallel on windows --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0cd4ca4..9954dd4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -35,7 +35,7 @@ jobs: - task: CMake@1 inputs: workingDir: 'build' - cmakeArgs: '--build . --config Release --verbose' + cmakeArgs: '--build . --config Release --verbose --parallel $(parallel)' - task: CmdLine@2 inputs: script: 'ctest.exe -T test -C Release' From 2a7b427df2c538a03696b8097b2bd4bdd1af831b Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Wed, 23 Feb 2022 10:56:03 -0800 Subject: [PATCH 6/7] Apply suggestions from code review --- src/errors.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/errors.cpp b/src/errors.cpp index bb82a09..2a90483 100644 --- a/src/errors.cpp +++ b/src/errors.cpp @@ -21,7 +21,6 @@ void throw_re(const char *s) { throw std::runtime_error(s); } #ifdef CAMP_ENABLE_CUDA -#define campCudaErrchk(ans) ::camp::cudaAssert((ans), #ans, __FILE__, __LINE__) cudaError_t cudaAssert(cudaError_t code, const char *call, @@ -47,8 +46,6 @@ cudaError_t cudaAssert(cudaError_t code, #ifdef CAMP_ENABLE_HIP -#define campHipErrchk(ans) ::camp::hipAssert((ans), #ans, __FILE__, __LINE__) - hipError_t hipAssert(hipError_t code, const char *call, const char *file, From 701327001b6b08f8f45dafc9d9639b77f119738b Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Wed, 23 Feb 2022 11:22:39 -0800 Subject: [PATCH 7/7] fix nasty cmake bug --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ee3e08..cb75c49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,7 +59,7 @@ foreach (backend ${camp_backends}) if ("${ENABLE_${suffix}}") set ("CAMP_ENABLE_${suffix}" On) endif() - if ("CAMP_ENABLE_${suffix}") + if (${CAMP_ENABLE_${suffix}}) if (backend IN_LIST camp_runtime_backends) set (backend ${backend}_runtime) endif()