-
Notifications
You must be signed in to change notification settings - Fork 56
Profiling Hooks
This page documents the interface between Kokkos and the profiling library. Every function prototype on this page is an interface hook. Profiling libraries may define any subset of the hooks listed here; hooks which are not defined by the library will be silently ignored by Kokkos. The hooks have C linkage, and we emphasize this with the extern "C"
required to define such symbols in C++. If the profiling library is written in C, the extern "C"
should be omitted.
struct KokkosPDeviceInfo {
uint32_t deviceID;
};
struct SpaceHandle {
char name[64];
};
This handle describes a Kokkos memory space. The name
member is a zero-padded string which currently can take the values "Host" or "Cuda".
extern "C" void kokkosp_init_library(int loadseq, uint64_t version, uint32_t ndevinfos, KokkosPDeviceInfo* devinfos);
This function will be called only once, prior to calling any other hooks in the profiling library. Currently the only argument which is non-zero is version
, which will specify the version of the interface (which will allow future changes to the interface). The version is an integer encoding a date as ((year*100)+month)*100
, and the current interface version is 20150628
.
extern "C" void kokkosp_finalize_library();
This function will be called only once, after all other calls to profiling hooks.
extern "C" void kokkosp_begin_parallel_for(const char* name, uint32_t devid, uint64_t* kernid);
extern "C" void kokkosp_begin_parallel_reduce(const char* name, uint32_t devid, uint64_t* kernid);
extern "C" void kokkosp_begin_parallel_scan(const char* name, uint32_t devid, uint64_t* kernid);
These functions are called before their respective parallel constructs execute (Kokkos::parallel_for
, Kokkos::parallel_reduce
, Kokkos::parallel_scan
). The name
argument is the name given by the user to the parallel construct, or in the case no name was given it is the compiler-dependent type name of the functor or lambda given to the construct. Currently devid
is always zero. kernid
is an output variable: the profiling library assigns a value to this, and that value will be given to the corresponding kokkosp_end_parallel_*
call at the end of the parallel construct.
extern "C" void kokkosp_end_parallel_for(uint64_t kernid);
extern "C" void kokkosp_end_parallel_reduce(uint64_t kernid);
extern "C" void kokkosp_end_parallel_scan(uint64_t kernid);
extern "C" void kokkosp_push_profile_region(const char* name);
This function will be called by Kokkos::Profiling::pushRegion(const std::string& cpp_name)
. The name
passed to it is the C equivalent of the cpp_name
given to Kokkos::Profiling::pushRegion
. As the function names imply, regions are meant to be treated in a stack fashion, ideally consistent with the calling stack of the application. One natural way to use them is to call pushRegion
at the beginning of an application function, and call popRegion
at the end of the application function. This helps the profiling library group other events like parallel_for
calls and memory allocations, and organize them according to the higher-level flow of the application for better presentation to the user.
extern "C" void kokkosp_pop_profile_region();
This function will be called by Kokkos::Profiling::popRegion()
. In accordance with the stack convention, the region being popped is the one named by the last call to pushRegion
.
extern "C" void kokkosp_allocate_data(SpaceHandle handle, const char* name, void* ptr, uint64_t size);
This function will be called whenever a shared allocation is created to support a Kokkos::View
. The handle
refers to the Kokkos MemorySpace where the memory resides, the name
is the name given by the user to the View
. The ptr
and size
parameters describe the block of memory as its starting pointer and size in bytes.
extern "C" void kokkosp_deallocate_data(SpaceHandle handle, const char* name, void* ptr, uint64_t size);
This function will be called whenever a shared allocation is destroyed. The handle
refers to the Kokkos MemorySpace where the memory resides, the name
is the name given by the user to the View
. The ptr
and size
parameters describe the block of memory as its starting pointer and size in bytes.
SAND2017-3786