Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require allocated type to have only a trivial constructor for make_device_unique and make_host_unique #204

Merged

Conversation

makortel
Copy link

This PR addresses @fwyzard's comment #172 (comment) and adds a requirement for T have (only) trivial constructor in CUDAService::make_device_unique() and CUDAService::make_host_unique().

In principle we could call a non-trivial constructor in make_host_unique, but since the only point of the pinned host memory is to transfer data to/from device memory, one needs (well, almost) the same struct for the make_device_unique as well. I deviced to go for consistency.

…vice_unique and make_host_unique

In principle we could call a non-trivial constructor in
make_host_unique, but since the only point of the pinned host memory
is to transfer data to/from device memory, one needs (well, almost)
the same struct for the make_device_unique as well. I deviced to go
for consistency.
@makortel
Copy link
Author

I'm not super happy with the outcome, but I don't know if we can do much better (unless we continue to just ignore constructors in make_{device,host}_unique).

uint32_t const *clusInModule_ = nullptr;
uint32_t const *moduleId_ = nullptr;
uint32_t const *clusModuleStart_ = nullptr;
uint32_t const *moduleStart_;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you remove the nullptr initialisation ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because those lead to constructor being non-trivial (since it would do some initialization).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <iostream>
class Xyz {
  int bar = 0;
};
int main(void) {
  std::cout << "Xyz " << std::is_trivially_constructible_v<Xyz> << std::endl;
  return 0;
}

gives

Xyz 0

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course sorry (trivial really means it does nothing...).

@@ -72,6 +72,7 @@ class CUDAService {
template <typename T>
typename cudaserviceimpl::make_device_unique_selector<T>::non_array
make_device_unique(cuda::stream_t<>& stream) {
static_assert(std::is_trivially_constructible<T>::value, "Allocating with non-trivial constructor on the device memory is not supported");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to fail the instantiation using std::enable_if_t<std::is_trivially_constructible<T>::value, typename ...> as the return type, instead of using a static_assert ?

Pro: the templates can be used with SFINAE.
Con: the error message may be harder to understand

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably not woken up enough, but what would be the benefit of SFINAE be with these?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, no, I don't think there is any advantage...
I guess we could start playing with concepts (later).

@fwyzard
Copy link

fwyzard commented Nov 29, 2018

And I do not understand the conflict, the branch does merge for me :-(

@fwyzard
Copy link

fwyzard commented Dec 7, 2018

No changes in performance (as expected) with respect to a67b49d:

Warming up
Running 4 times over 4200 events with 1 jobs, each with 8 threads, 8 streams and 1 GPUs
  1757.8 ±   1.3 ev/s (4000 events)
  1764.3 ±   1.5 ev/s (4000 events)
  1762.1 ±   1.5 ev/s (4000 events)
  1759.4 ±   1.5 ev/s (4000 events)

@fwyzard fwyzard merged commit 13a99e3 into cms-patatrack:CMSSW_10_4_X_Patatrack Dec 7, 2018
@fwyzard fwyzard added this to the CMSSW_10_4_0_pre3_Patatrack milestone Jan 8, 2019
fwyzard pushed a commit that referenced this pull request Oct 8, 2020
fwyzard pushed a commit that referenced this pull request Oct 19, 2020
fwyzard pushed a commit that referenced this pull request Oct 20, 2020
fwyzard pushed a commit that referenced this pull request Oct 23, 2020
fwyzard pushed a commit that referenced this pull request Nov 6, 2020
fwyzard pushed a commit that referenced this pull request Nov 16, 2020
fwyzard pushed a commit that referenced this pull request Dec 25, 2020
fwyzard pushed a commit that referenced this pull request Dec 29, 2020
fwyzard pushed a commit that referenced this pull request Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants