Skip to content

Commit

Permalink
Merge pull request #621 from harrism/fix-constexpr-cuda_stream_default
Browse files Browse the repository at this point in the history
Make `rmm::cuda_stream_default` a `constexpr`
  • Loading branch information
jrhemstad authored Nov 2, 2020
2 parents ae915ea + ad240c1 commit f70306c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

- PR #592 Add `auto_flush` to `make_logging_adaptor`
- PR #602 Fix `device_scalar` and its tests so that they use the correct CUDA stream
- PR #621 Make `rmm::cuda_stream_default` a `constexpr`

# RMM 0.16.0 (21 Oct 2020)

Expand Down
6 changes: 5 additions & 1 deletion benchmarks/replay/replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <string>
#include <thread>

#include "rmm/cuda_stream_view.hpp"
#include "spdlog/common.h"

/// MR factory functions
Expand Down Expand Up @@ -242,7 +243,10 @@ std::vector<std::vector<rmm::detail::event>> parse_per_thread_events(std::string
RMM_EXPECTS(std::all_of(all_events.begin(),
all_events.end(),
[](auto const& e) {
return e.stream.is_default() or e.stream.is_per_thread_default();
cudaStream_t cs;
memcpy(&cs, &e.stream, sizeof(cudaStream_t));
auto s = rmm::cuda_stream_view{cs};
return s.is_default() or s.is_per_thread_default();
}),
"Non-default streams not currently supported.");

Expand Down
35 changes: 11 additions & 24 deletions benchmarks/utilities/log_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <rmm/mr/device/device_memory_resource.hpp>

#include "rapidcsv.h"
#include "rmm/cuda_stream_view.hpp"

#include <cstdint>
#include <iomanip>
Expand Down Expand Up @@ -51,26 +50,25 @@ struct event {

event(action a, std::size_t s, uintptr_t p) : act{a}, size{s}, pointer{p} {}

event(
std::size_t tid, action a, std::size_t sz, uintptr_t p, rmm::cuda_stream_view s, std::size_t i)
event(std::size_t tid, action a, std::size_t sz, uintptr_t p, uintptr_t s, std::size_t i)
: thread_id{tid}, act{a}, size{sz}, pointer{p}, stream{s}, index{i}
{
}

event(std::size_t tid, action a, std::size_t sz, void* p, rmm::cuda_stream_view s, std::size_t i)
event(std::size_t tid, action a, std::size_t sz, void* p, uintptr_t s, std::size_t i)
: event{tid, a, sz, reinterpret_cast<uintptr_t>(p), s, i}
{
}

friend std::ostream& operator<<(std::ostream& os, event const& e);

action act{}; ///< Indicates if the event is an allocation or a free
std::size_t size{}; ///< The size of the memory allocated or freed
uintptr_t pointer{}; ///< The pointer returned from an allocation, or the
///< pointer freed
std::size_t thread_id; ///< ID of the thread that initiated the event
rmm::cuda_stream_view stream; ///< The CUDA stream on which the event occurred
std::size_t index; ///< Original ordering index of the event
action act{}; ///< Indicates if the event is an allocation or a free
std::size_t size{}; ///< The size of the memory allocated or freed
uintptr_t pointer{}; ///< The pointer returned from an allocation, or the
///< pointer freed
std::size_t thread_id; ///< ID of the thread that initiated the event
uintptr_t stream; ///< Numeric representation of the CUDA stream on which the event occurred
std::size_t index; ///< Original ordering index of the event
};

inline std::ostream& operator<<(std::ostream& os, event const& e)
Expand All @@ -83,8 +81,6 @@ inline std::ostream& operator<<(std::ostream& os, event const& e)
return os;
}

inline uintptr_t hex_string_to_int(std::string const& s) { return std::stoll(s, nullptr, 16); }

/**
* @brief Parse a log timestamp into a std::chrono::time_point
*
Expand Down Expand Up @@ -138,16 +134,7 @@ inline std::vector<event> parse_csv(std::string const& filename)

std::vector<uintptr_t> pointers = csv.GetColumn<uintptr_t>("Pointer", parse_pointer);
std::vector<std::size_t> sizes = csv.GetColumn<std::size_t>("Size");

auto parse_stream = [](std::string const& s, rmm::cuda_stream_view& stream) {
cudaStream_t cs;
uintptr_t ls = std::stoll(s);
std::memcpy(&cs, &ls, sizeof(cudaStream_t));
stream = rmm::cuda_stream_view{cs};
};

std::vector<rmm::cuda_stream_view> streams =
csv.GetColumn<rmm::cuda_stream_view>("Stream", parse_stream);
std::vector<uintptr_t> streams = csv.GetColumn<uintptr_t>("Stream");

auto const size_list = {tids.size(), actions.size(), pointers.size(), streams.size()};

Expand All @@ -165,7 +152,7 @@ inline std::vector<event> parse_csv(std::string const& filename)
events[i] = event{tids[i], act, sizes[i], pointers[i], streams[i], i};
}
return events;
} // namespace detail
}

} // namespace detail
} // namespace rmm
2 changes: 1 addition & 1 deletion include/rmm/cuda_stream_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class cuda_stream_view {
/**
* @brief Static cuda_stream_view of the default stream (stream 0), for convenience
*/
static cuda_stream_view cuda_stream_default{};
static constexpr cuda_stream_view cuda_stream_default{};

/**
* @brief Static cuda_stream_view of cudaStreamLegacy, for convenience
Expand Down

0 comments on commit f70306c

Please sign in to comment.