Skip to content

Commit

Permalink
Add NVTX marker
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcrimsontianyu committed Oct 28, 2024
1 parent 88cb16b commit 21eca70
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
9 changes: 2 additions & 7 deletions cpp/include/kvikio/file_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,6 @@ class FileHandle {
std::size_t devPtr_offset,
bool sync_default_stream = true)
{
KVIKIO_NVTX_FUNC_RANGE("FileHandle::read()", size);

if (_compat_mode) {
return detail::posix_device_read(
_fd_direct_off, devPtr_base, size, file_offset, devPtr_offset);
Expand Down Expand Up @@ -381,8 +379,6 @@ class FileHandle {
std::size_t devPtr_offset,
bool sync_default_stream = true)
{
KVIKIO_NVTX_FUNC_RANGE("FileHandle::write()", size);

_nbytes = 0; // Invalidate the computed file size

if (_compat_mode) {
Expand Down Expand Up @@ -438,8 +434,7 @@ class FileHandle {
std::size_t gds_threshold = defaults::gds_threshold(),
bool sync_default_stream = true)
{
KVIKIO_NVTX_FUNC_RANGE("FileHandle::pread()", size);

KVIKIO_NVTX_MARKER("FileHandle::pread()", size);
if (is_host_memory(buf)) {
auto op = [this](void* hostPtr_base,
std::size_t size,
Expand Down Expand Up @@ -516,7 +511,7 @@ class FileHandle {
std::size_t gds_threshold = defaults::gds_threshold(),
bool sync_default_stream = true)
{
KVIKIO_NVTX_FUNC_RANGE("FileHandle::pwrite()", size);
KVIKIO_NVTX_MARKER("FileHandle::pwrite()", size);
if (is_host_memory(buf)) {
auto op = [this](const void* hostPtr_base,
std::size_t size,
Expand Down
30 changes: 30 additions & 0 deletions cpp/include/kvikio/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ struct libkvikio_domain {
} \
}
#define GET_KVIKIO_NVTX_FUNC_RANGE_MACRO(_1, _2, NAME, ...) NAME

#define KVIKIO_NVTX_MARKER_IMPL(msg, val) \
nvtx3::mark_in<libkvikio_domain>( \
nvtx3::event_attributes{REGISTER_STRING(msg), nvtx3::payload{convert_to_64bit(val)}})

#endif

/**
Expand Down Expand Up @@ -342,4 +347,29 @@ struct libkvikio_domain {
} while (0)
#endif

/**
* @brief Convenience macro for generating an NVTX marker in the `libkvikio` domain to annotate a
* certain time point.
*
* Takes two arguments (message, payload). Use this macro to annotate asynchronous I/O operations,
* where the payload refers to the I/O size.
*
* Example:
* ```
* std::future<void> some_function(){
* size_t io_size{2077};
* KVIKIO_NVTX_MARKER("I/O operation", io_size);
* perform_async_io_operation(io_size);
* ...
* }
* ```
*/
#ifdef KVIKIO_CUDA_FOUND
#define KVIKIO_NVTX_MARKER(message, payload) KVIKIO_NVTX_MARKER_IMPL(message, payload)
#else
#define KVIKIO_NVTX_MARKER(message, payload) \
do { \
} while (0)
#endif

} // namespace kvikio

0 comments on commit 21eca70

Please sign in to comment.