diff --git a/include/gauxc/enums.hpp b/include/gauxc/enums.hpp index af44dce8..ce7c19e1 100644 --- a/include/gauxc/enums.hpp +++ b/include/gauxc/enums.hpp @@ -51,5 +51,11 @@ enum class ExecutionSpace { Device ///< Execute task on the device (e.g. GPU) }; +/// Supported Algorithms / Integrands +enum class SupportedAlg { + XC, + DEN, + SNLINK +}; } // namespace GauXC diff --git a/include/gauxc/gauxc_config.hpp.in b/include/gauxc/gauxc_config.hpp.in index 7b5974b2..a7f0ce69 100644 --- a/include/gauxc/gauxc_config.hpp.in +++ b/include/gauxc/gauxc_config.hpp.in @@ -18,7 +18,16 @@ #cmakedefine GAUXC_HAS_HDF5 #cmakedefine GAUXC_USE_FAST_RSQRT +#ifdef GAUXC_HAS_HOST +#cmakedefine GAUXC_CPU_XC_MAX_AM @GAUXC_CPU_XC_MAX_AM@ +#cmakedefine GAUXC_CPU_SNLINK_MAX_AM @GAUXC_CPU_SNLINK_MAX_AM@ +#endif + #cmakedefine GAUXC_HAS_DEVICE +#ifdef GAUXC_HAS_DEVICE +#cmakedefine GAUXC_GPU_XC_MAX_AM @GAUXC_GPU_XC_MAX_AM@ +#cmakedefine GAUXC_GPU_SNLINK_MAX_AM @GAUXC_GPU_SNLINK_MAX_AM@ +#endif #if defined(__CUDACC__) || defined(__HIPCC__) #define HOST_DEVICE_ACCESSIBLE __host__ __device__ diff --git a/include/gauxc/util/environment.hpp b/include/gauxc/util/environment.hpp new file mode 100644 index 00000000..953c5334 --- /dev/null +++ b/include/gauxc/util/environment.hpp @@ -0,0 +1,42 @@ +/** + * GauXC Copyright (c) 2020-2024, The Regents of the University of California, + * through Lawrence Berkeley National Laboratory (subject to receipt of + * any required approvals from the U.S. Dept. of Energy). All rights reserved. + * + * See LICENSE.txt for details + */ +#pragma once +#include +#include + +namespace GauXC { + +inline int gauxc_max_am(ExecutionSpace ex, SupportedAlg alg) { + switch(ex) { + #ifdef GAUXC_HAS_HOST + case ExecutionSpace::Host: + switch(alg) { + case SupportedAlg::XC: + case SupportedAlg::DEN: + return GAUXC_CPU_XC_MAX_AM; + case SupportedAlg::SNLINK: + return GAUXC_CPU_SNLINK_MAX_AM; + default: return -1; + } + #endif + #ifdef GAUXC_HAS_DEVICE + case ExecutionSpace::Device: + switch(alg) { + case SupportedAlg::XC: + case SupportedAlg::DEN: + return GAUXC_GPU_XC_MAX_AM; + case SupportedAlg::SNLINK: + return GAUXC_GPU_SNLINK_MAX_AM; + default: return -1; + } + #endif + default: return -1; + } +} + +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e6448970..7e51e9fa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -100,6 +100,17 @@ add_subdirectory( external ) add_library( gauxc::gauxc ALIAS gauxc ) + +if(GAUXC_HAS_HOST) + set(GAUXC_CPU_XC_MAX_AM 6) + set(GAUXC_CPU_SNLINK_MAX_AM 6) +endif() + +if(GAUXC_HAS_DEVICE) + set(GAUXC_GPU_XC_MAX_AM 4) + set(GAUXC_GPU_SNLINK_MAX_AM 2) +endif() + # Generate config file configure_file( ${PROJECT_SOURCE_DIR}/include/gauxc/gauxc_config.hpp.in @@ -151,10 +162,10 @@ set_target_properties(gauxc "GAUXC_HAS_MPI" ${GAUXC_HAS_MPI} "GAUXC_HAS_OPENMP" ${GAUXC_HAS_OPENMP} "GAUXC_HAS_HDF5" ${GAUXC_HAS_HDF5} - "GAUXC_CPU_XC_MAX_AM" 6 - "GAUXC_CPU_SNLINK_MAX_AM" 6 - "GAUXC_GPU_XC_MAX_AM" 4 - "GAUXC_GPU_SNLINK_MAX_AM" 2 + "GAUXC_CPU_XC_MAX_AM" ${GAUXC_CPU_XC_MAX_AM} + "GAUXC_CPU_SNLINK_MAX_AM" ${GAUXC_CPU_SNLINK_MAX_AM} + "GAUXC_GPU_XC_MAX_AM" ${GAUXC_GPU_XC_MAX_AM} + "GAUXC_GPU_SNLINK_MAX_AM" ${GAUXC_GPU_SNLINK_MAX_AM} ) set_property(TARGET gauxc APPEND PROPERTY EXPORT_PROPERTIES "${export_properties}") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ee20d59b..2c76faf6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -54,6 +54,7 @@ add_executable( gauxc_test basisset_test.cxx load_balancer_test.cxx xc_integrator.cxx + environment.cxx collocation.cxx weights.cxx standards.cxx diff --git a/tests/environment.cxx b/tests/environment.cxx new file mode 100644 index 00000000..ae9ec82b --- /dev/null +++ b/tests/environment.cxx @@ -0,0 +1,46 @@ +/** + * GauXC Copyright (c) 2020-2024, The Regents of the University of California, + * through Lawrence Berkeley National Laboratory (subject to receipt of + * any required approvals from the U.S. Dept. of Energy). All rights reserved. + * + * See LICENSE.txt for details + */ +#include "ut_common.hpp" +#include + +using namespace GauXC; +TEST_CASE("Environment", "[env]") { + + SECTION("Host") { + auto xc = gauxc_max_am(ExecutionSpace::Host, SupportedAlg::XC ); + auto den = gauxc_max_am(ExecutionSpace::Host, SupportedAlg::DEN ); + auto snk = gauxc_max_am(ExecutionSpace::Host, SupportedAlg::SNLINK); + +#ifdef GAUXC_HAS_HOST + REQUIRE(xc == GAUXC_CPU_XC_MAX_AM); + REQUIRE(den == GAUXC_CPU_XC_MAX_AM); + REQUIRE(snk == GAUXC_CPU_SNLINK_MAX_AM); +#else + REQUIRE(xc == -1); + REQUIRE(den == -1); + REQUIRE(snk == -1); +#endif + } + + SECTION("Device") { + auto xc = gauxc_max_am(ExecutionSpace::Device, SupportedAlg::XC ); + auto den = gauxc_max_am(ExecutionSpace::Device, SupportedAlg::DEN ); + auto snk = gauxc_max_am(ExecutionSpace::Device, SupportedAlg::SNLINK); + +#ifdef GAUXC_HAS_DEVICE + REQUIRE(xc == GAUXC_GPU_XC_MAX_AM); + REQUIRE(den == GAUXC_GPU_XC_MAX_AM); + REQUIRE(snk == GAUXC_GPU_SNLINK_MAX_AM); +#else + REQUIRE(xc == -1); + REQUIRE(den == -1); + REQUIRE(snk == -1); +#endif + } + +}