Skip to content
Open
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
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,23 @@ else()
set(KOKKOSTOOLS_HAS_VTUNE OFF)
endif()

# Check for NVML (required for energy profiler)
set(MIN_CUDA_VERSION 12.6)
find_package(CUDAToolkit ${MIN_CUDA_VERSION} QUIET)
if (CUDAToolkit_FOUND)
Comment on lines +106 to +109
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you seen https://docs.nvidia.com/nsight-systems/UserGuide/index.html#nvml-power-and-temperature-metrics-preview ?

It would be great to actually better document this tool and compare it to what nsigh-systems may provide. Does your tool make anything special to help correlate Kokkos regions with consumption, trigger anything special ? Or is it "just" launching a thread that samples the energy consumption ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what about asynchronicity ? I mean:

{
    Kokkos::Profiling::ScopeRegion region("my region");

    Kokkos::parallel_for(Kokkos::RangePolicy(exec, 0, N), ...); // async
}

If the tool reports the consumption of the my region region, if you're not Kokkos::fenceing, what is the meaning of the measurements reported by Kokkos Tools, especially when the kernel is actually running after the scoped region ends ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! I've seen this page one time but since I focused more on Variorum support at some point I haven't had the chance of reading it further. As of now, the tool is only launching a thread that samples the energy consumption.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what about asynchronicity ? I mean:

{
    Kokkos::Profiling::ScopeRegion region("my region");

    Kokkos::parallel_for(Kokkos::RangePolicy(exec, 0, N), ...); // async
}

If the tool reports the consumption of the my region region, if you're not Kokkos::fenceing, what is the meaning of the measurements reported by Kokkos Tools, especially when the kernel is actually running after the scoped region ends ?

For now, the system doesn't do anything special to correlate power consumption with a specific region or kernel. The timing system is meant to help visualize what the current situation is, so there's room for improvement (meaning adding more correlation using multiple metrics), especially since the daemon system would still allow for method/data propagation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romintomasetti we will check if Nsight does actually do something useful. It at least sounds like the exact same thing we are doing.
About the fencing: Nvidia at the moment allows power measurements every 100ms. But it seems to return only the power average of the last 25ms of that window, see http://arxiv.org/abs/2312.02741. Thus the tool will at the current state of Nvidas tools only be useful for measuring entire regions and even then it will need repetitions with shifts and post processing in order to get anything that is relatable to an algorithm. Due to these problems the tool currently does not require fencing, this should be done by the user.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on our ToDo list :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JBludau Do you still have plans to look at the AMD Profiling metrics, as mentioned above? Do you have updates you can share - particularly those that are pertinent to this PR - from your end?

Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pr has been split into smaller ones to make it easier to review. Once we have these in, we can think about adding something for amd

find_package(CUDA::nvml QUIET)
if(TARGET CUDA::nvml)
message(STATUS "Found CUDA NVML (version ${CUDAToolkit_VERSION}), energy profiler will be built")
set(KOKKOSTOOLS_HAS_NVML ON)
else()
message(STATUS "CUDA::nvml target not found, energy profiler will be skipped")
set(KOKKOSTOOLS_HAS_NVML OFF)
endif()
else()
message(STATUS "CUDAToolkit ${MIN_CUDA_VERSION} or higher not found, energy profiler will be skipped")
set(KOKKOSTOOLS_HAS_NVML OFF)
endif()

# make Kokkos profiling interface available for native profilers
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/profiling/all)

Expand Down Expand Up @@ -150,6 +167,11 @@ if(NOT WIN32)
add_subdirectory(profiling/chrome-tracing)
add_subdirectory(profiling/space-time-stack)
add_subdirectory(profiling/perfetto-connector)
if(KOKKOSTOOLS_HAS_NVML)
add_subdirectory(profiling/energy-profiler)
else()
message(STATUS "Skipping energy-profiler (NVML not available)")
endif()
endif()

# External lib connectors
Expand Down
11 changes: 11 additions & 0 deletions profiling/energy-profiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kp_add_library(kp_energy_profiler
kp_energy_profiler.cpp
timing_utils.cpp
timing_export.cpp
nvml_provider.cpp
power_sampler.cpp
daemon.cpp
)

target_link_libraries(kp_energy_profiler PRIVATE CUDA::nvml)
target_compile_definitions(kp_energy_profiler PRIVATE KOKKOS_ENERGY_PROFILER_HAS_NVML)
45 changes: 45 additions & 0 deletions profiling/energy-profiler/daemon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER

#include "daemon.hpp"
#include <stdexcept>
#include <thread>

void Daemon::start() {
if (!running_) {
running_ = true;
thread_ = std::thread(&Daemon::run, this);
} else {
throw std::runtime_error("Daemon already started");
}
}

void Daemon::run() {
while (running_) {
auto next_run = std::chrono::high_resolution_clock::now() + interval_;
func_();
std::this_thread::sleep_until(next_run);
}
}

void Daemon::stop() {
if (running_) {
running_ = false;
thread_.join();
} else {
throw std::runtime_error("Daemon not started");
}
}
39 changes: 39 additions & 0 deletions profiling/energy-profiler/daemon.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER

#pragma once

#include <functional>
#include <thread>
#include <chrono>

class Daemon {
public:
Daemon(std::function<void()> func, int interval_ms)
: interval_(interval_ms), func_(func){};

void start();
void run();
void stop();
bool is_running() const { return running_; }
std::thread& get_thread() { return thread_; }

private:
std::chrono::milliseconds interval_;
bool running_{false};
std::function<void()> func_;
std::thread thread_;
};
38 changes: 38 additions & 0 deletions profiling/energy-profiler/energy_profiler_constants.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER

#pragma once

#include <cstddef>

namespace KokkosTools {
namespace EnergyProfiler {

// Sampling interval in milliseconds
constexpr int SAMPLING_INTERVAL_MS = 20;

// Buffer size for hostname
const size_t HOSTNAME_BUFFER_SIZE = 256;

// Table formatting constants for timing export
const int COLUMN_WIDTH_CATEGORY = 10;
const int COLUMN_WIDTH_NAME = 32;
const int COLUMN_WIDTH_TYPE = 14;
const int COLUMN_WIDTH_TIME = 17;
const int COLUMN_WIDTH_DURATION = 13;

} // namespace EnergyProfiler
} // namespace KokkosTools
Loading