Skip to content

Commit

Permalink
Benchmark thrust::copy with non-trivially relocatable type (#1989)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber authored Jul 22, 2024
1 parent e5fcebe commit 496d88d
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions thrust/benchmarks/bench/copy/basic.cu
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static void basic(nvbench::state& state, nvbench::type_list<T>)
{
const auto elements = static_cast<std::size_t>(state.get_int64("Elements"));

thrust::device_vector<T> input(elements, 1);
thrust::device_vector<T> input(elements, T{1});
thrust::device_vector<T> output(elements);

state.add_element_count(elements);
Expand All @@ -52,7 +52,31 @@ static void basic(nvbench::state& state, nvbench::type_list<T>)
});
}

using types = nvbench::type_list<nvbench::uint8_t, nvbench::uint16_t, nvbench::uint32_t, nvbench::uint64_t>;
// Non-trivially-copyable/relocatable type which is not allowed to be copied using std::memcpy or cudaMemcpy
struct non_trivial
{
int a;
int b;

non_trivial() = default;

_CCCL_HOST_DEVICE explicit non_trivial(int i)
: a(i)
, b(i)
{}

// the user-defined copy constructor prevents the type from being trivially copyable
_CCCL_HOST_DEVICE non_trivial(const non_trivial& nt)
: a(nt.a)
, b(nt.b)
{}
};

static_assert(!::cuda::std::is_trivially_copyable<non_trivial>::value, ""); // as required by the C++ standard
static_assert(!thrust::is_trivially_relocatable<non_trivial>::value, ""); // thrust uses this check internally

using types =
nvbench::type_list<nvbench::uint8_t, nvbench::uint16_t, nvbench::uint32_t, nvbench::uint64_t, non_trivial>;

NVBENCH_BENCH_TYPES(basic, NVBENCH_TYPE_AXES(types))
.set_name("base")
Expand Down

0 comments on commit 496d88d

Please sign in to comment.