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

Encapsulate more common code to CUDAESProduct #336

Open
makortel opened this issue Apr 29, 2019 · 0 comments
Open

Encapsulate more common code to CUDAESProduct #336

makortel opened this issue Apr 29, 2019 · 0 comments

Comments

@makortel
Copy link

From @fwyzard in https://github.com/cms-patatrack/cmssw/pull/301/files#r279369606

The pattern seems to be:

  • start with a class/struct for the actual data on th GPU
  Payload *cablingMapHost = nullptr; // pointer to struct in CPU
  • define a wrapper
  struct PayloadWrapper {
    ~PayloadWrapper();
    Payload *payload = nullptr; // pointer to struct in GPU
  };
  • add a CUDAESProduct data mamber:
  CUDAESProduct<PayloadWrapper> payload_;
  • produce it for the gpu like this
Payload const* getGPUProductAsync(cuda::stream_t<>& cudaStream) const {
  const auto& data = payload_.dataForCurrentDeviceAsync(cudaStream, [this](PayloadWrapper& data, cuda::stream_t<>& stream) {
      // allocate
      cudaCheck(cudaMalloc(&data.payload, sizeof(Payload)));

      // transfer
      cudaCheck(cudaMemcpyAsync(data.payload, this->cablingMapHost, sizeof(Payload), cudaMemcpyDefault, stream.id()));
  });
  return data.payload;
}

Would it make sense to encapsulate more of the common part into CUDAESProduct ?

And/or to drop the PayloadWrapper in favour of a unique_ptr, possibly with a custom destructor ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant