Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ nwx_cxx_api_docs("README.md" "${project_inc_dir}" "${project_src_dir}")
cmaize_option_list(
BUILD_TESTING OFF "Should we build the tests?"
BUILD_PYBIND11_PYBINDINGS ON "Should we build pybind11 python bindings?"
BUILD_CPP_JOULES OFF "Enable energy usage tracking with CPP Joules library?"
BUILD_CUDA_BINDINGS OFF "Enable CUDA Bindings"
BUILD_HIP_BINDINGS OFF "Enable HIP Bindings"
BUILD_SYCL_BINDINGS OFF "Enable SYCL Bindings"
Expand Down Expand Up @@ -67,6 +68,18 @@ if("${BUILD_PAPI_BINDINGS}")
include(build_papi)
endif ()

if("${BUILD_CPP_JOULES}")
cmaize_find_or_build_dependency(
cpp_joules
BUILD_CPP_JOULES
URL github.com/rishalab/CPPJoules
VERSION main
BUILD_TARGET CPP_Joules
FIND_TARGET CPP_Joules::CPP_Joules
)
list(APPEND project_depends cpp_joules)
endif()

cmaize_find_or_build_dependency(
cereal
URL github.com/USCiLab/cereal
Expand All @@ -84,6 +97,10 @@ cmaize_add_library(
DEPENDS "${project_depends}"
)

if("${BUILD_CPP_JOULES}")
target_compile_definitions("${PROJECT_NAME}" PRIVATE BUILD_CPP_JOULES)
endif()

# N.B. this is a no-op if BUILD_PYBIND11_PYBINDINGS is not turned on
include(nwx_pybind11)
nwx_add_pybind11_module(
Expand Down
7 changes: 5 additions & 2 deletions src/parallelzone/hardware/cpu/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
* limitations under the License.
*/

#include "energy_monitor.hpp"
#include <parallelzone/hardware/cpu/cpu.hpp>

namespace parallelzone::hardware {

typename CPU::profile_return_type CPU::profile_it_(task_type&& task) const {
profile_information i;
EnergyMonitor monitor;
monitor.start();
const auto t1 = std::chrono::high_resolution_clock::now();
auto result = task();
const auto t2 = std::chrono::high_resolution_clock::now();
i.wall_time = (t2 - t1);
monitor.stop();
i.wall_time = (t2 - t1);
return std::make_pair(std::move(result), std::move(i));
}

Expand Down
53 changes: 53 additions & 0 deletions src/parallelzone/hardware/cpu/energy_monitor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2025 NWChemEx-Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once
#ifdef BUILD_CPP_JOULES
#include <cppJoules.h>

namespace parallelzone::hardware {

class EnergyMonitor {
public:
using energy_type = long long;
bool is_active() { return true; }
void start() { m_tracker_.start(); }

void stop() {
m_tracker_.stop();
m_tracker_.calculate_energy();
m_tracker_.print_energy();
}

private:
EnergyTracker m_tracker_;
};

} // namespace parallelzone::hardware

#else
namespace parallelzone::hardware {

class EnergyMonitor {
public:
bool is_active() { return false; }
void start() {}
void stop() {}
};

} // namespace parallelzone::hardware

#endif
2 changes: 2 additions & 0 deletions tests/cxx/unit_tests/parallelzone/hardware/cpu/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

#include "../../catch.hpp"
#include <iostream>
#include <numeric>
#include <parallelzone/hardware/cpu/cpu.hpp>

using namespace parallelzone;
Expand Down