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

[WIP] Kokkos metadata handling in specific service #358

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
2 changes: 1 addition & 1 deletion src/caliper/controllers/controllers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const char* builtin_option_specs =
" \"type\" : \"bool\","
" \"description\" : \"Profile Kokkos functions\","
" \"category\" : \"region\","
" \"services\" : [ \"kokkostime\" ]"
" \"services\" : [ \"kokkostime\", \"kokkosadiak\" ]"
"},"
"{"
" \"name\" : \"main_thread_only\","
Expand Down
8 changes: 6 additions & 2 deletions src/services/kokkos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ set(CALIPER_KOKKOS_SOURCES
KokkosProfilingSymbols.cpp
KokkosLookup.cpp
KokkosTime.cpp
)

)
if(WITH_ADIAK)
include_directories(${adiak_INCLUDE_DIRS})
list(APPEND CALIPER_KOKKOS_SOURCES "KokkosMetadataService.cpp")
add_caliper_service("kokkosadiak")
endif()
add_library(caliper-kokkos OBJECT ${CALIPER_KOKKOS_SOURCES})

add_service_objlib("caliper-kokkos")
Expand Down
88 changes: 88 additions & 0 deletions src/services/kokkos/KokkosMetadataService.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// Created by Poliakoff, David Zoeller on 4/21/21.
//

#include "caliper/CaliperService.h"

#include "caliper/Caliper.h"
#include "../../caliper/MemoryPool.h"

#include "caliper/common/Log.h"
#include "caliper/common/RuntimeConfig.h"
#include "caliper/Annotation.h"

#include <iterator>
#include <cstdint>

#include "types.hpp"
#include "adiak.hpp"
using namespace cali;

namespace {

class KokkosAdiak {
static const ConfigSet::Entry s_configdata[];

KokkosAdiak(Caliper *c, Channel *chn) {
adiak_init(nullptr);
adiak::user();
adiak::launchdate();
adiak::executablepath();
adiak::libraries();
adiak::cmdline();
adiak::clustername();
adiak::jobsize();
}

public:

void declare(const char* key, const char* value){
std::string parseme(value);
try {
size_t end;
float v = std::stof(parseme,&end);
adiak::value(key, v);
return;
}
catch(std::invalid_argument){
}
try {
size_t end;
int i = std::stoi(parseme,&end);
adiak::value(key, i);
return;
}
catch(std::invalid_argument){
}
adiak::value(key,value);
}
static void kokkosadiak_register(Caliper *c, Channel *chn) {

auto *instance = new KokkosAdiak(c, chn);
chn->events().post_init_evt.connect(
[instance](Caliper *c, Channel *chn) {
kokkosp_callbacks.kokkosp_declare_metadata.connect([&](const char* name, const char* value){
instance->declare(name,value);
});
});
chn->events().finish_evt.connect(
[instance](Caliper*, Channel*){
delete instance;
});

Log(1).stream() << chn->name() << ": Registered kokkosadiak service" << std::endl;
}
};

const ConfigSet::Entry KokkosAdiak::s_configdata[] = {
ConfigSet::Terminator
};

} // namespace [anonymous]


namespace cali {

CaliperService kokkosadiak_service{"kokkosadiak", ::KokkosAdiak::kokkosadiak_register};

}
3 changes: 3 additions & 0 deletions src/services/kokkos/KokkosProfilingSymbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ kokkosp_begin_deep_copy(const SpaceHandle dst_handle, const char *dst_name,
extern "C" void kokkosp_end_deep_copy() {
kokkosp_callbacks.kokkosp_end_deep_copy_callback();
}
extern "C" void kokkosp_declare_metadata(const char* key, const char* value){
kokkosp_callbacks.kokkosp_declare_metadata(key, value);
}
9 changes: 6 additions & 3 deletions src/services/kokkos/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ namespace kokkos {
using end_deep_copy_callback = util::callback<void()>;

using begin_fence_callback = util::callback<void(const char*, const uint32_t, uint64_t*)>;
using end_fence_callback = util::callback<void(uint64_t)>;
struct callbacks {
using end_fence_callback = util::callback<void(uint64_t)>;
using metadata_callback = util::callback<void(const char*, const char*)>;
struct callbacks {

init_callback kokkosp_init_callback;
finalize_callback kokkosp_finalize_callback;
Expand All @@ -58,7 +59,9 @@ namespace kokkos {

begin_fence_callback kokkosp_begin_fence_callback;
end_fence_callback kokkosp_end_fence_callback;
};

metadata_callback kokkosp_declare_metadata;
};

} // end namespace kokkos

Expand Down