Skip to content

Commit

Permalink
Merge pull request #1833 from arcaneframework/dev/gg-add-auto-hint-on…
Browse files Browse the repository at this point in the history
…-device

Add environment variable 'ARCANE_CUDA_MEMORY_HINT_ON_DEVICE' to automatically call 'cudaMemAdvise' on allocated unified memory
  • Loading branch information
grospelliergilles authored Dec 10, 2024
2 parents 7fa360a + 6cf6b6e commit 6aae950
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion arcane/src/arcane/accelerator/cuda/CudaAccelerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ class UnifiedMemoryCudaMemoryAllocator
if (auto v = Convert::Type<Int32>::tryParseFromEnvironment("ARCANE_ACCELERATOR_MEMORY_POOL", true))
use_memory_pool = (v.value() & static_cast<int>(MemoryPoolFlags::UVM)) != 0;
_setUseMemoryPool(use_memory_pool);

if (auto v = Convert::Type<Int32>::tryParseFromEnvironment("ARCANE_CUDA_MEMORY_HINT_ON_DEVICE", true))
m_use_hint_as_mainly_device = (v.value() != 0);
}

public:
Expand All @@ -468,7 +471,8 @@ class UnifiedMemoryCudaMemoryAllocator
void _applyHint(void* p, size_t new_size, MemoryAllocationArgs args)
{
eMemoryLocationHint hint = args.memoryLocationHint();

if (m_use_hint_as_mainly_device)
hint = eMemoryLocationHint::MainlyDevice;
// Utilise le device actif pour positionner le GPU par défaut
// On ne le fait que si le \a hint le nécessite pour éviter d'appeler
// cudaGetDevice() à chaque fois.
Expand Down Expand Up @@ -501,6 +505,8 @@ class UnifiedMemoryCudaMemoryAllocator
private:

bool m_use_ats = false;
//! Si vrai, par défaut on considère toutes les allocations comme eMemoryLocationHint::MainlyDevice
bool m_use_hint_as_mainly_device = false;
};

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

0 comments on commit 6aae950

Please sign in to comment.