Skip to content

Commit 9ab5fc3

Browse files
[rocm-libraries] ROCm/rocm-libraries#6233 (commit a9a0519)
Fix memory leaks in rocRAND and hipRAND ## Motivation Fixing memory leaks is good. ## Technical Details Fixed assorted memory leaks in the rocRAND/hipRAND unit tests, and one memory leak in mtgp32.hpp - the test code showed a pattern which could cause rocRAND's mtgp32_generator_template to not free m_engines. ## Test Plan Run unit tests to verify nothing is broken and leaks are gone. ## Test Result Memory leaks no longer reported by ASAN. ## Submission Checklist - [ ] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
1 parent 9ecd577 commit 9ab5fc3

File tree

2 files changed

+254
-152
lines changed

2 files changed

+254
-152
lines changed

library/src/rng/mtgp32.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ namespace rocrand_impl::host
8080
struct mtgp32_device_engine : ::rocrand_device::mtgp32_engine
8181
{
8282
// suppress warning about no initialization for __shared__ variables
83-
__host__ __device__ mtgp32_device_engine(){};
83+
__host__ __device__
84+
mtgp32_device_engine() {};
8485

8586
__forceinline__ __host__ __device__
8687
unsigned int next()
@@ -366,7 +367,7 @@ class mtgp32_generator_template : public generator_impl_base
366367
return *this;
367368
}
368369

369-
~mtgp32_generator_template()
370+
void free_engines()
370371
{
371372
if(m_engines != nullptr)
372373
{
@@ -375,13 +376,19 @@ class mtgp32_generator_template : public generator_impl_base
375376
}
376377
}
377378

379+
~mtgp32_generator_template()
380+
{
381+
free_engines();
382+
}
383+
378384
static constexpr rocrand_rng_type type()
379385
{
380386
return ROCRAND_RNG_PSEUDO_MTGP32;
381387
}
382388

383389
void reset() override final
384390
{
391+
free_engines();
385392
m_engines_initialized = false;
386393
}
387394

0 commit comments

Comments
 (0)