diff --git a/rocclr/runtime/device/device.hpp b/rocclr/runtime/device/device.hpp index 41a4a9a51d..74d551b895 100644 --- a/rocclr/runtime/device/device.hpp +++ b/rocclr/runtime/device/device.hpp @@ -1537,6 +1537,11 @@ public: CL_DEVICE_SVM_FINE_GRAIN_SYSTEM)) != 0 ? true : false; } + //! check svm FGS support capability. + inline bool isFineGrainedSystem() const { + return (info().svmCapabilities_ & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM) != 0 ? true : false; + } + //! Return this device's type. cl_device_type type() const { return info().type_ & ~(CL_DEVICE_TYPE_DEFAULT | CL_HSA_ENABLED_AMD diff --git a/rocclr/runtime/platform/context.cpp b/rocclr/runtime/platform/context.cpp index f21eea2faf..b097ee7c1b 100644 --- a/rocclr/runtime/platform/context.cpp +++ b/rocclr/runtime/platform/context.cpp @@ -40,10 +40,22 @@ Context::Context( svmAllocDevice_.push_back(device); } } - //make sure the first device is GPU - if ((svmAllocDevice_.size() > 1) - && (svmAllocDevice_.front()->type() == CL_DEVICE_TYPE_CPU)) { - std::swap(svmAllocDevice_.front(), svmAllocDevice_.back()); + if (svmAllocDevice_.size() > 1) { + //make sure the CPU is the last device to do allocation. + if ((svmAllocDevice_.front()->type() == CL_DEVICE_TYPE_CPU)) { + std::swap(svmAllocDevice_.front(), svmAllocDevice_.back()); + } + + uint isFirstDeviceFGSEnabled = svmAllocDevice_.front()->isFineGrainedSystem(); + for (auto& dev : svmAllocDevice_) { + //allocation on fine - grained system incapable device first + if (isFirstDeviceFGSEnabled && (dev->type() == CL_DEVICE_TYPE_GPU) + && (!(dev->isFineGrainedSystem()))) { + std::swap(svmAllocDevice_.front(), dev); + break; + } + } + } }