Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowed Caliper to control Kokkos fencing behavior #373

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions src/services/kokkos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include_directories(include)
set(CALIPER_KOKKOS_SOURCES
KokkosProfilingSymbols.cpp
KokkosLookup.cpp
Expand Down
59 changes: 55 additions & 4 deletions src/services/kokkos/KokkosProfilingSymbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,52 @@
#include "caliper/cali.h"
#include "types.hpp"
#include <cstdint>
#include <impl/Kokkos_Profiling_Interface.hpp>
cali::kokkos::callbacks kokkosp_callbacks;
using cali::kokkos::SpaceHandle;
namespace kokkos {
cali::ConfigManager mgr;
cali::ConfigManager mgr;
bool can_control_fences = false;
bool config_needs_fences = true;
Kokkos::Tools::Experimental::ToolProgrammingInterface kokkos_interface;
template <typename Container, typename FenceIf>
void fence_if_needed(const Container &in, uint32_t dev_id,
const FenceIf &predicate) {
if (can_control_fences && !in.empty() && predicate()) {
kokkos_interface.fence(dev_id);
}
}
extern "C" void kokkosp_print_help(char* progName){
} // namespace kokkos
extern "C" void kokkosp_print_help(char *progName) {
std::cerr << "Caliper: available configs: \n";
for(auto conf: kokkos::mgr.available_config_specs() ) {
std::cerr << kokkos::mgr.get_documentation_for_spec(conf.c_str()) << std::endl;
for (auto conf : kokkos::mgr.available_config_specs()) {
std::cerr << kokkos::mgr.get_documentation_for_spec(conf.c_str())
<< std::endl;
}
}
extern "C" void kokkosp_request_tool_settings(
int num_actions, Kokkos::Tools::Experimental::ToolSettings *settings) {
if ((num_actions > 0) && (settings != nullptr)) {
settings->requires_global_fencing = false;
}
}

extern "C" void kokkosp_provide_tool_programming_interface(
int num_actions,
Kokkos::Tools::Experimental::ToolProgrammingInterface interface) {
kokkos::can_control_fences = true;
kokkos::kokkos_interface = interface;
}
extern "C" void kokkosp_parse_args(int argc, char *argv_raw[]) {
if (argc > 2) {
std::cerr << "Error: the Kokkos Caliper connector takes only one argument"
<< std::endl;
}
if (argc == 2) {
if (std::string(argv_raw[1]).find("cuda-activity-report") !=
std::string::npos) {
kokkos::config_needs_fences = false;
}
kokkos::mgr.add(argv_raw[1]);
if (kokkos::mgr.error()) {
std::cerr << "Kokkos Caliper connector error: " << kokkos::mgr.error_msg()
Expand All @@ -46,40 +75,62 @@ extern "C" void kokkosp_finalize_library() {
extern "C" void kokkosp_begin_parallel_for(const char *name,
const uint32_t devID,
uint64_t *kID) {
kokkos::fence_if_needed(kokkosp_callbacks.kokkosp_begin_parallel_for_callback,
devID, [=]() { return kokkos::config_needs_fences; });
kokkosp_callbacks.kokkosp_begin_parallel_for_callback(name, devID, kID);
*kID = devID;
}
extern "C" void kokkosp_begin_parallel_reduce(const char *name,
const uint32_t devID,
uint64_t *kID) {
kokkos::fence_if_needed(
kokkosp_callbacks.kokkosp_begin_parallel_reduce_callback, devID,
[=]() { return kokkos::config_needs_fences; });
kokkosp_callbacks.kokkosp_begin_parallel_reduce_callback(name, devID, kID);
*kID = devID;
}
extern "C" void kokkosp_begin_parallel_scan(const char *name,
const uint32_t devID,
uint64_t *kID) {
kokkos::fence_if_needed(
kokkosp_callbacks.kokkosp_begin_parallel_scan_callback, devID,
[=]() { return kokkos::config_needs_fences; });
kokkosp_callbacks.kokkosp_begin_parallel_scan_callback(name, devID, kID);
*kID = devID;
}
extern "C" void kokkosp_begin_fence(const char *name, const uint32_t devID,
uint64_t *kID) {
kokkosp_callbacks.kokkosp_begin_fence_callback(name, devID, kID);
}

extern "C" void kokkosp_end_parallel_for(const uint64_t kID) {
kokkos::fence_if_needed(kokkosp_callbacks.kokkosp_end_parallel_for_callback,
kID, [=]() { return kokkos::config_needs_fences; });
kokkosp_callbacks.kokkosp_end_parallel_for_callback(kID);
}
extern "C" void kokkosp_end_parallel_reduce(const uint64_t kID) {
kokkos::fence_if_needed(
kokkosp_callbacks.kokkosp_end_parallel_reduce_callback, kID,
[=]() { return kokkos::config_needs_fences; });
kokkosp_callbacks.kokkosp_end_parallel_reduce_callback(kID);
}
extern "C" void kokkosp_end_parallel_scan(const uint64_t kID) {
kokkos::fence_if_needed(kokkosp_callbacks.kokkosp_end_parallel_scan_callback,
kID, [=]() { return kokkos::config_needs_fences; });
kokkosp_callbacks.kokkosp_end_parallel_scan_callback(kID);
}
extern "C" void kokkosp_end_fence(const uint64_t kID) {
kokkosp_callbacks.kokkosp_end_fence_callback(kID);
}

extern "C" void kokkosp_push_profile_region(char *regionName) {
kokkos::fence_if_needed(kokkosp_callbacks.kokkosp_push_region_callback, 0,
[=]() { return true; });
kokkosp_callbacks.kokkosp_push_region_callback(regionName);
}
extern "C" void kokkosp_pop_profile_region() {
kokkos::fence_if_needed(kokkosp_callbacks.kokkosp_push_region_callback, 0,
[=]() { return true; });
kokkosp_callbacks.kokkosp_pop_region_callback();
}
extern "C" void kokkosp_allocate_data(const SpaceHandle space,
Expand Down
4 changes: 2 additions & 2 deletions src/services/kokkos/KokkosProfilingSymbols.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef CALIPER_SERVICES_KOKKOS_PROFILING_SYMBOLS_HPP
#define CALIPER_SERVICES_KOKKOS_PROFILING_SYMBOLS_HPP


//comment
#include "types.hpp"

#include <impl/Kokkos_Profiling_Interface.hpp>

#endif

Loading