Skip to content

Commit

Permalink
Move mutability of a member from TestCUDAAnalyzerGPUKernel to TestCUD…
Browse files Browse the repository at this point in the history
…AAnalyzerGPU

The point is that the member functions mutating the visible state
should not be const even if they are thread safe.
TestCUDAAnalyzerGPUKernel::analyzeAsync() mutates the visible state
(by "filling a histogram"), so it should not be const. Declaring
TestCUDAAnalyzerGPU::gpuAlgo_ as mutable is an improvement since
filling the histogram does not really change the visible state of the
EDAnalyzer (towards the framework).
  • Loading branch information
makortel committed Dec 13, 2019
1 parent d6b4490 commit 0a5c1ab
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion HeterogeneousCore/CUDATest/plugins/TestCUDAAnalyzerGPU.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class TestCUDAAnalyzerGPU : public edm::global::EDAnalyzer<> {
edm::EDGetTokenT<CUDAProduct<CUDAThing>> const srcToken_;
double const minValue_;
double const maxValue_;
std::unique_ptr<TestCUDAAnalyzerGPUKernel> gpuAlgo_;
// the public interface is thread safe
CMS_THREAD_SAFE mutable std::unique_ptr<TestCUDAAnalyzerGPUKernel> gpuAlgo_;
};

TestCUDAAnalyzerGPU::TestCUDAAnalyzerGPU(edm::ParameterSet const& iConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TestCUDAAnalyzerGPUKernel::TestCUDAAnalyzerGPUKernel(cudaStream_t stream) {
cudaCheck(cudaStreamSynchronize(stream));
}

void TestCUDAAnalyzerGPUKernel::analyzeAsync(const float *d_input, cudaStream_t stream) const {
void TestCUDAAnalyzerGPUKernel::analyzeAsync(const float *d_input, cudaStream_t stream) {
analyze<<<int(ceil(float(NUM_VALUES) / 256)), 256, 0, stream>>>(d_input, sum_.get(), NUM_VALUES);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class TestCUDAAnalyzerGPUKernel {
TestCUDAAnalyzerGPUKernel(cudaStream_t stream);
~TestCUDAAnalyzerGPUKernel() = default;

// returns (owning) pointer to device memory
void analyzeAsync(const float* d_input, cudaStream_t stream) const;
// thread safe
void analyzeAsync(const float* d_input, cudaStream_t stream);
float value(cudaStream_t stream) const;

private:
mutable cudautils::device::unique_ptr<float[]> sum_; // all writes are atomic in CUDA
cudautils::device::unique_ptr<float[]> sum_; // all writes are atomic in CUDA
};

#endif

0 comments on commit 0a5c1ab

Please sign in to comment.