From 3a61c2577e8e64812aaef2e3f6e4da712d876602 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Fri, 24 Jul 2015 23:23:39 +0200 Subject: [PATCH 1/2] CL: switch to chunks if clEnqueuWriteBuffer fails Probably fixes #2559 even though chunking is not stable at the moment. --- libethash-cl/ethash_cl_miner.cpp | 37 +++++++++++--------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/libethash-cl/ethash_cl_miner.cpp b/libethash-cl/ethash_cl_miner.cpp index 982e4ec9d..8042888cb 100644 --- a/libethash-cl/ethash_cl_miner.cpp +++ b/libethash-cl/ethash_cl_miner.cpp @@ -361,15 +361,22 @@ bool ethash_cl_miner::init( try { m_dagChunksCount = 1; + ETHCL_LOG("Creating one big buffer for the DAG"); m_dagChunks.push_back(cl::Buffer(m_context, CL_MEM_READ_ONLY, _dagSize)); - ETHCL_LOG("Created one big buffer for the DAG"); + ETHCL_LOG("Loading single big chunk kernels"); + m_hashKernel = cl::Kernel(program, "ethash_hash"); + m_searchKernel = cl::Kernel(program, "ethash_search"); + ETHCL_LOG("Mapping one big chunk."); + m_queue.enqueueWriteBuffer(m_dagChunks[0], CL_TRUE, 0, _dagSize, _dag); } catch (cl::Error const& err) { int errCode = err.err(); if (errCode != CL_INVALID_BUFFER_SIZE || errCode != CL_MEM_OBJECT_ALLOCATION_FAILURE) - ETHCL_LOG("Allocating single buffer failed with: " << err.what() << "(" << errCode << ")"); + ETHCL_LOG("Allocating/mapping single buffer failed with: " << err.what() << "(" << errCode << ")"); cl_ulong result; + // if we fail midway on the try above make sure we start clean + m_dagChunks.clear(); device.getInfo(CL_DEVICE_MAX_MEM_ALLOC_SIZE, &result); ETHCL_LOG( "Failed to allocate 1 big chunk. Max allocateable memory is " @@ -387,32 +394,9 @@ bool ethash_cl_miner::init( (i == 3) ? (_dagSize - 3 * ((_dagSize >> 9) << 7)) : (_dagSize >> 9) << 7 )); } - } - - if (m_dagChunksCount == 1) - { - ETHCL_LOG("Loading single big chunk kernels"); - m_hashKernel = cl::Kernel(program, "ethash_hash"); - m_searchKernel = cl::Kernel(program, "ethash_search"); - } - else - { ETHCL_LOG("Loading chunk kernels"); m_hashKernel = cl::Kernel(program, "ethash_hash_chunks"); m_searchKernel = cl::Kernel(program, "ethash_search_chunks"); - } - - // create buffer for header - ETHCL_LOG("Creating buffer for header."); - m_header = cl::Buffer(m_context, CL_MEM_READ_ONLY, 32); - - if (m_dagChunksCount == 1) - { - ETHCL_LOG("Mapping one big chunk."); - m_queue.enqueueWriteBuffer(m_dagChunks[0], CL_TRUE, 0, _dagSize, _dag); - } - else - { // TODO Note: If we ever change to _dagChunksNum other than 4, then the size would need recalculation void* dag_ptr[4]; for (unsigned i = 0; i < m_dagChunksCount; i++) @@ -426,6 +410,9 @@ bool ethash_cl_miner::init( m_queue.enqueueUnmapMemObject(m_dagChunks[i], dag_ptr[i]); } } + // create buffer for header + ETHCL_LOG("Creating buffer for header."); + m_header = cl::Buffer(m_context, CL_MEM_READ_ONLY, 32); // create mining buffers for (unsigned i = 0; i != c_bufferCount; ++i) From c429b03ddb964c602c1b5fcd719fc55a6a24f1be Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Tue, 28 Jul 2015 09:55:27 +0200 Subject: [PATCH 2/2] Disable chunking until further notice --- libethash-cl/ethash_cl_miner.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libethash-cl/ethash_cl_miner.cpp b/libethash-cl/ethash_cl_miner.cpp index 8042888cb..2183de320 100644 --- a/libethash-cl/ethash_cl_miner.cpp +++ b/libethash-cl/ethash_cl_miner.cpp @@ -371,6 +371,9 @@ bool ethash_cl_miner::init( } catch (cl::Error const& err) { + ETHCL_LOG("Allocating/mapping single buffer failed with: " << err.what() << "(" << err.err() << "). GPU can't allocate the DAG in a single chunk. Bailing."); + return false; +#if 0 // Disabling chunking for release since it seems not to work. Never manages to mine a block. TODO: Fix when time is found. int errCode = err.err(); if (errCode != CL_INVALID_BUFFER_SIZE || errCode != CL_MEM_OBJECT_ALLOCATION_FAILURE) ETHCL_LOG("Allocating/mapping single buffer failed with: " << err.what() << "(" << errCode << ")"); @@ -409,6 +412,7 @@ bool ethash_cl_miner::init( memcpy(dag_ptr[i], (char *)_dag + i*((_dagSize >> 9) << 7), (i == 3) ? (_dagSize - 3 * ((_dagSize >> 9) << 7)) : (_dagSize >> 9) << 7); m_queue.enqueueUnmapMemObject(m_dagChunks[i], dag_ptr[i]); } +#endif } // create buffer for header ETHCL_LOG("Creating buffer for header.");