Skip to content
Snippets Groups Projects
Commit db873d4a authored by Ravi Ayyala's avatar Ravi Ayyala
Browse files

added a wrapper class for UniformGPUScheme class.

parent 2dee476c
Branches
No related merge requests found
Pipeline #77848 failed with stages
in 33 minutes and 43 seconds
......@@ -73,6 +73,52 @@ namespace communication {
* When running multiple \ref UniformGPUScheme concurrently, different MPI tags
* have to be used for the schemes: the tag can be passed in the constructor.
*/
template<typename Stencil>
class GPUStreamRAII {
public:
GPUStreamRAII() {
for (uint_t i = 0; i < Stencil::Q; ++i)
WALBERLA_GPU_CHECK(gpuStreamCreate(&streams_[i]))
}
~GPUStreamRAII() {
for (uint_t i = 0; i < Stencil::Q; ++i) {
WALBERLA_GPU_CHECK(gpuStreamDestroy(streams_[i]));
}
}
// Delete copy constructor and copy assignment
GPUStreamRAII(const GPUStreamRAII&) = delete;
GPUStreamRAII& operator=(const GPUStreamRAII&) = delete;
GPUStreamRAII(GPUStreamRAII&& other) noexcept {
for (uint_t i = 0; i < Stencil::Q; ++i) {
streams_[i] = other.streams_[i];
other.streams_[i] = nullptr;
}
}
GPUStreamRAII& operator=(GPUStreamRAII&& other) noexcept {
if (this != &other) {
for (uint_t i = 0; i < Stencil::Q; ++i) {
if (streams_[i]) {
WALBERLA_GPU_CHECK(gpuStreamDestroy(streams_[i]));
}
streams_[i] = other.streams_[i];
other.streams_[i] = nullptr;
}
}
return *this;
}
//gpuStream_t get(uint_t index) const { return streams_[index]; }
private:
std::array<gpuStream_t, Stencil::Q> streams_;
};
template<typename Stencil>
class UniformGPUScheme
{
......@@ -88,11 +134,12 @@ namespace communication {
const bool sendDirectlyFromGPU = false,
const bool useLocalCommunication = true,
const int tag = 5432 );
~UniformGPUScheme()
/*~UniformGPUScheme()
{
for (uint_t i = 0; i < Stencil::Q; ++i)
WALBERLA_GPU_CHECK(gpuStreamDestroy(streams_[i]))
}
WALBERLA_GPU_CHECK(gpuStreamDestroy(ravi_[i]))
}*/
~UniformGPUScheme() = default;
void addPackInfo( const shared_ptr<GeneratedGPUPackInfo> &pi );
......@@ -135,10 +182,15 @@ namespace communication {
Set<SUID> requiredBlockSelectors_;
Set<SUID> incompatibleBlockSelectors_;
std::array<gpuStream_t, Stencil::Q> streams_;
//std::array<gpuStream_t, Stencil::Q> streams_; // array of RAII wrappers
std::array<GPUStreamRAII<Stencil>, Stencil::Q> streams_;
};
} // namespace communication
} // namespace gpu
} // namespace walberla
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment