Skip to content

How to explicitly mark a struct device_copiable #8734

Answered by AlexeySachkov
Luigi-Crisci asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @Luigi-Crisci,

You can find an example in our tests: basic_tests/is_device_copyable.cpp.

Let's say you have your struct:

// Not copyable type, but it will be declared as device copyable.
struct BCopyable {
int i;
BCopyable(int _i) : i(_i) {}
BCopyable(const BCopyable &x) : i(x.i) {}
};

Specializing is_device_copyable trait for it would look like:

template <> struct is_device_copyable<BCopyable> : std::true_type {};

You can also find examples in 3rd-party repos, such as kokkos/kokkos,…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Luigi-Crisci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants