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

Add override of 'IMemoryAllocator::memoryResource()' for accelerator allocators #1807

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions arcane/src/arcane/accelerator/cuda/CudaAccelerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ class UnifiedMemoryCudaMemoryAllocator
if (p && s > 0)
_applyHint(ptr.baseAddress(), ptr.size(), new_args);
}
eMemoryResource memoryResource() const override { return eMemoryResource::UnifiedMemory; }

protected:

Expand Down Expand Up @@ -542,6 +543,7 @@ class HostPinnedCudaMemoryAllocator
_setUseMemoryPool(use_memory_pool);
m_block_wrapper.initialize(128, use_memory_pool);
}
eMemoryResource memoryResource() const override { return eMemoryResource::HostPinned; }
};

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -607,6 +609,7 @@ class DeviceCudaMemoryAllocator
_setUseMemoryPool(use_memory_pool);
m_block_wrapper.initialize(128, use_memory_pool);
}
eMemoryResource memoryResource() const override { return eMemoryResource::Device; }
};

/*---------------------------------------------------------------------------*/
Expand Down
3 changes: 3 additions & 0 deletions arcane/src/arcane/accelerator/hip/HipAccelerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class UnifiedMemoryHipMemoryAllocator
{
return ::hipFree(ptr);
}
eMemoryResource memoryResource() const override { return eMemoryResource::UnifiedMemory; }
};

/*---------------------------------------------------------------------------*/
Expand All @@ -124,6 +125,7 @@ class HostPinnedHipMemoryAllocator
{
return ::hipHostFree(ptr);
}
eMemoryResource memoryResource() const override { return eMemoryResource::HostPinned; }
};

/*---------------------------------------------------------------------------*/
Expand All @@ -142,6 +144,7 @@ class DeviceHipMemoryAllocator
{
return ::hipFree(ptr);
}
eMemoryResource memoryResource() const override { return eMemoryResource::Device; }
};

/*---------------------------------------------------------------------------*/
Expand Down
3 changes: 3 additions & 0 deletions arcane/src/arcane/accelerator/sycl/SyclAccelerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class UnifiedMemorySyclMemoryAllocator
{
sycl::free(ptr, q);
}
eMemoryResource memoryResource() const override { return eMemoryResource::UnifiedMemory; }
};

/*---------------------------------------------------------------------------*/
Expand All @@ -126,6 +127,7 @@ class HostPinnedSyclMemoryAllocator
{
sycl::free(ptr, q);
}
eMemoryResource memoryResource() const override { return eMemoryResource::HostPinned; }
};

/*---------------------------------------------------------------------------*/
Expand All @@ -144,6 +146,7 @@ class DeviceSyclMemoryAllocator
{
sycl::free(ptr, q);
}
eMemoryResource memoryResource() const override { return eMemoryResource::Device; }
};

/*---------------------------------------------------------------------------*/
Expand Down
16 changes: 16 additions & 0 deletions arcane/src/arcane/accelerator/tests/TestInit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <gtest/gtest.h>

#include "arcane/utils/MemoryUtils.h"
#include "arcane/utils/MemoryAllocator.h"
#include "arcane/accelerator/core/Runner.h"
#include "arcane/accelerator/core/RunQueue.h"

Expand Down Expand Up @@ -38,6 +40,20 @@
Runner runner(exec_policy);
RunQueue queue(makeQueue(runner));
ASSERT_TRUE(queue.executionPolicy() == exec_policy);

eMemoryResource mr = eMemoryResource::Host;
ASSERT_EQ(MemoryUtils::getAllocator(mr)->memoryResource(),mr);

if (queue.isAcceleratorPolicy()){
mr = eMemoryResource::HostPinned;
ASSERT_EQ(MemoryUtils::getAllocator(mr)->memoryResource(),mr);

Check warning on line 49 in arcane/src/arcane/accelerator/tests/TestInit.cc

View check run for this annotation

Codecov / codecov/patch

arcane/src/arcane/accelerator/tests/TestInit.cc#L48-L49

Added lines #L48 - L49 were not covered by tests

mr = eMemoryResource::Device;
ASSERT_EQ(MemoryUtils::getAllocator(mr)->memoryResource(),mr);

Check warning on line 52 in arcane/src/arcane/accelerator/tests/TestInit.cc

View check run for this annotation

Codecov / codecov/patch

arcane/src/arcane/accelerator/tests/TestInit.cc#L51-L52

Added lines #L51 - L52 were not covered by tests

mr = eMemoryResource::UnifiedMemory;
ASSERT_EQ(MemoryUtils::getAllocator(mr)->memoryResource(),mr);

Check warning on line 55 in arcane/src/arcane/accelerator/tests/TestInit.cc

View check run for this annotation

Codecov / codecov/patch

arcane/src/arcane/accelerator/tests/TestInit.cc#L54-L55

Added lines #L54 - L55 were not covered by tests
}
}

/*---------------------------------------------------------------------------*/
Expand Down
Loading