Fixed memory allocation on old low memory AMD GPUs.

This commit is contained in:
XMRig 2019-11-15 19:42:35 +07:00
parent 0497ab072b
commit f9bc3fb09b
3 changed files with 17 additions and 8 deletions

View file

@ -99,12 +99,14 @@ void xmrig::OclBaseRunner::init()
{
m_queue = OclLib::createCommandQueue(m_ctx, data().device.id());
size_t size = align(bufferSize());
size_t size = align(bufferSize());
const size_t limit = data().device.freeMemSize();
if (size < oneGiB && data().device.vendorId() == OCL_VENDOR_AMD && data().device.freeMemSize() >= oneGiB) {
m_buffer = OclSharedState::get(data().device.index()).createBuffer(m_ctx, size, m_offset);
if (size < oneGiB && data().device.vendorId() == OCL_VENDOR_AMD && limit >= oneGiB) {
m_buffer = OclSharedState::get(data().device.index()).createBuffer(m_ctx, size, m_offset, limit);
}
else {
if (!m_buffer) {
m_buffer = OclLib::createBuffer(m_ctx, CL_MEM_READ_WRITE, size);
}

View file

@ -40,12 +40,19 @@
constexpr size_t oneGiB = 1024 * 1024 * 1024;
cl_mem xmrig::OclSharedData::createBuffer(cl_context context, size_t size, size_t &offset)
cl_mem xmrig::OclSharedData::createBuffer(cl_context context, size_t size, size_t &offset, size_t limit)
{
std::lock_guard<std::mutex> lock(m_mutex);
offset += size * m_offset++;
size = std::max(size * m_threads, oneGiB);
const size_t pos = offset + (size * m_offset);
size = std::max(size * m_threads, oneGiB);
if (size > limit) {
return nullptr;
}
offset = pos;
++m_offset;
if (!m_buffer) {
m_buffer = OclLib::createBuffer(context, CL_MEM_READ_WRITE, size);

View file

@ -45,7 +45,7 @@ class OclSharedData
public:
OclSharedData() = default;
cl_mem createBuffer(cl_context context, size_t size, size_t &offset);
cl_mem createBuffer(cl_context context, size_t size, size_t &offset, size_t limit);
uint64_t adjustDelay(size_t id);
uint64_t resumeDelay(size_t id);
void release();