From 2a0d565b8b29f5835710b2074088a233cba13698 Mon Sep 17 00:00:00 2001 From: psychocrypt <psychocryptHPC@gmail.com> Date: Mon, 15 Oct 2018 22:43:15 +0200 Subject: [PATCH] fix broken AMD OpenCL compile The AMD compiler for OpenCL shipped with the driver 14XX is broken and can not compile xmr-stak since the monero v8 changes are introduced. - workaround a simple compare. - add new device define `OPENCL_DRIVER_MAJOR` --- xmrstak/backend/amd/amd_gpu/gpu.cpp | 5 ++++ .../amd/amd_gpu/opencl/fast_int_math_v2.cl | 23 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/xmrstak/backend/amd/amd_gpu/gpu.cpp b/xmrstak/backend/amd/amd_gpu/gpu.cpp index 7c7aff7..2c29275 100644 --- a/xmrstak/backend/amd/amd_gpu/gpu.cpp +++ b/xmrstak/backend/amd/amd_gpu/gpu.cpp @@ -420,6 +420,11 @@ size_t InitOpenCLGpu(cl_context opencl_ctx, GpuContext* ctx, const char* source_ options += " -DMEMORY=" + std::to_string(hashMemSize); options += " -DALGO=" + std::to_string(miner_algo[ii]); options += " -DCN_UNROLL=" + std::to_string(ctx->unroll); + /* AMD driver output is something like: `1445.5 (VM)` + * and is mapped to `14` only. The value is only used for a compiler + * workaround. + */ + options += " -DOPENCL_DRIVER_MAJOR=" + std::to_string(std::stoi(openCLDriverVer.data()) / 100); /* create a hash for the compile time cache * used data: diff --git a/xmrstak/backend/amd/amd_gpu/opencl/fast_int_math_v2.cl b/xmrstak/backend/amd/amd_gpu/opencl/fast_int_math_v2.cl index 607806b..55768d3 100644 --- a/xmrstak/backend/amd/amd_gpu/opencl/fast_int_math_v2.cl +++ b/xmrstak/backend/amd/amd_gpu/opencl/fast_int_math_v2.cl @@ -2,6 +2,10 @@ R"===( /* * @author SChernykh */ + +// cryptonight_monero_v8 +#if(ALGO==11) + static const __constant uint RCP_C[256] = { 0xfe01be73u,0xfd07ff01u,0xfa118c5au,0xf924fb13u,0xf630cddbu,0xf558f73cu,0xf25f2934u,0xf1a3f37bu, @@ -68,9 +72,19 @@ inline uint2 fast_div_v2(const __local uint *RCP, ulong a, uint b) const ulong k = mul_hi(as_uint2(a).s0, r) + ((ulong)(r) * as_uint2(a).s1) + a; ulong q; - ((uint*)&q)[0] = as_uint2(k).s1;; - ((uint*)&q)[1] = (k < a) ? 1 : 0; - + ((uint*)&q)[0] = as_uint2(k).s1; + +#if defined(cl_amd_device_attribute_query) && (OPENCL_DRIVER_MAJOR == 14) + /* The AMD driver 14.XX is not able to compile `(k < a)` + * https://github.com/fireice-uk/xmr-stak/issues/1922 + * This is a workaround for the broken compiler. + */ + const long xx = k - a; + ((uint*)&q)[1] = (xx < 0) ? 1U : 0U; +#else + ((uint*)&q)[1] = (k < a) ? 1U : 0U; +#endif + const long tmp = a - q * b; const bool overshoot = (tmp < 0); const bool undershoot = (tmp >= b); @@ -105,4 +119,7 @@ inline uint fast_sqrt_v2(const ulong n1) return result; } + +#endif + )===" -- GitLab