Skip to content

Commit

Permalink
Add Runtime Environment Query Functions (#126)
Browse files Browse the repository at this point in the history
* Add runtime environment query functions

* Update gauxc_config.hpp.in
  • Loading branch information
wavefunction91 authored May 8, 2024
1 parent cf6b85c commit 6a8f4bf
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 4 deletions.
6 changes: 6 additions & 0 deletions include/gauxc/enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions include/gauxc/gauxc_config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
42 changes: 42 additions & 0 deletions include/gauxc/util/environment.hpp
Original file line number Diff line number Diff line change
@@ -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 <gauxc/gauxc_config.hpp>
#include <gauxc/enums.hpp>

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;
}
}

}
19 changes: 15 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions tests/environment.cxx
Original file line number Diff line number Diff line change
@@ -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 <gauxc/util/environment.hpp>

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
}

}

0 comments on commit 6a8f4bf

Please sign in to comment.