Skip to content

Commit

Permalink
nvtx support macos (#474)
Browse files Browse the repository at this point in the history
Closes #471

Authors:
  - Mads R. B. Kristensen (https://github.com/madsbk)

Approvers:
  - Vukasin Milovanovic (https://github.com/vuule)
  - Lawrence Mitchell (https://github.com/wence-)

URL: #474
  • Loading branch information
madsbk authored Sep 30, 2024
1 parent 44b3f97 commit 35ec784
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion cpp/include/kvikio/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <iostream>
#include <map>
#include <optional>
#include <stdexcept>
#include <tuple>
#include <type_traits>

#include <nvtx3/nvtx3.hpp>

Expand Down Expand Up @@ -69,6 +71,29 @@ inline constexpr std::size_t page_size = 4096;
return reinterpret_cast<CUdeviceptr>(devPtr);
}

/**
* @brief Help function to convert value to 64 bit signed integer
*/
template <typename T, std::enable_if_t<std::is_integral_v<T>>* = nullptr>
[[nodiscard]] std::int64_t convert_to_64bit(T value)
{
if constexpr (std::numeric_limits<T>::max() > std::numeric_limits<std::int64_t>::max()) {
if (value > std::numeric_limits<std::int64_t>::max()) {
throw std::overflow_error("convert_to_64bit(x): x too large to fit std::int64_t");
}
}
return std::int64_t(value);
}

/**
* @brief Help function to convert value to 64 bit float
*/
template <typename T, std::enable_if_t<std::is_floating_point_v<T>>* = nullptr>
[[nodiscard]] double convert_to_64bit(T value)
{
return double(value);
}

/**
* @brief Check if `ptr` points to host memory (as opposed to device memory)
*
Expand Down Expand Up @@ -280,7 +305,7 @@ struct libkvikio_domain {
{ \
nvtx3::event_attributes \
{ \
msg, nvtx3::payload { val } \
msg, nvtx3::payload { convert_to_64bit(val) } \
} \
}
#define GET_KVIKIO_NVTX_FUNC_RANGE_MACRO(_1, _2, NAME, ...) NAME
Expand Down

0 comments on commit 35ec784

Please sign in to comment.