Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMD: use more 32bit operations #2084

Merged
merged 1 commit into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions xmrstak/backend/amd/amd_gpu/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#endif



#ifdef _WIN32
#include <windows.h>
#include <Shlobj.h>
Expand Down Expand Up @@ -412,12 +411,12 @@ size_t InitOpenCLGpu(cl_context opencl_ctx, GpuContext* ctx, const char* source_

std::string options;
options += " -DITERATIONS=" + std::to_string(hashIterations);
options += " -DMASK=" + std::to_string(threadMemMask);
options += " -DWORKSIZE=" + std::to_string(ctx->workSize);
options += " -DMASK=" + std::to_string(threadMemMask) + "U";
options += " -DWORKSIZE=" + std::to_string(ctx->workSize) + "U";
options += " -DSTRIDED_INDEX=" + std::to_string(strided_index);
options += " -DMEM_CHUNK_EXPONENT=" + std::to_string(mem_chunk_exp);
options += " -DMEM_CHUNK_EXPONENT=" + std::to_string(mem_chunk_exp) + "U";
options += " -DCOMP_MODE=" + std::to_string(ctx->compMode ? 1u : 0u);
options += " -DMEMORY=" + std::to_string(hashMemSize);
options += " -DMEMORY=" + std::to_string(hashMemSize) + "LLU";
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)`
Expand Down
34 changes: 17 additions & 17 deletions xmrstak/backend/amd/amd_gpu/opencl/cryptonight.cl
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ __kernel void JOIN(cn0,ALGO)(__global ulong *input, __global uint4 *Scratchpad,
AES2[i] = rotate(tmp, 16U);
AES3[i] = rotate(tmp, 24U);
}

__local ulong State_buf[8 * 25];

barrier(CLK_LOCAL_MEM_FENCE);
Expand Down Expand Up @@ -474,12 +474,12 @@ __kernel void JOIN(cn0,ALGO)(__global ulong *input, __global uint4 *Scratchpad,
}

mem_fence(CLK_LOCAL_MEM_FENCE);

// cryptonight_heavy || cryptonight_haven || cryptonight_bittube2
#if (ALGO == 4 || ALGO == 9 || ALGO == 10)
__local uint4 xin[8][8];
{


/* Also left over threads perform this loop.
* The left over thread results will be ignored
Expand Down Expand Up @@ -530,7 +530,7 @@ __kernel void JOIN(cn0,ALGO)(__global ulong *input, __global uint4 *Scratchpad,

)==="
R"===(

// cryptonight_monero_v8 && NVIDIA
#if(ALGO==11 && defined(__NV_CL_C_VERSION))
# define SCRATCHPAD_CHUNK(N) (*(__local uint4*)((__local uchar*)(scratchpad_line) + (idxS ^ (N << 4))))
Expand Down Expand Up @@ -630,23 +630,23 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states
tweak1_2 ^= as_uint2(states[24]);
#endif
}

mem_fence(CLK_LOCAL_MEM_FENCE);

#if(COMP_MODE==1)
// do not use early return here
if(gIdx < Threads)
#endif
{
ulong idx0 = a[0] & MASK;
uint idx0 = as_uint2(a[0]).s0 & MASK;

#pragma unroll CN_UNROLL
for(int i = 0; i < ITERATIONS; ++i)
{
ulong c[2];
// cryptonight_monero_v8 && NVIDIA
#if(ALGO==11 && defined(__NV_CL_C_VERSION))
ulong idxS = idx0 & 0x30;
uint idxS = idx0 & 0x30U;
*scratchpad_line = SCRATCHPAD_CHUNK_GLOBAL;
#endif

Expand Down Expand Up @@ -682,23 +682,23 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states
# endif
b_x[0].s2 ^= ((table >> index) & 0x30U) << 24;
SCRATCHPAD_CHUNK(0) = b_x[0];
idx0 = c[0] & MASK;
idx0 = as_uint2(c[0]).s0 & MASK;
// cryptonight_monero_v8
#elif(ALGO==11)
SCRATCHPAD_CHUNK(0) = b_x[0] ^ ((uint4 *)c)[0];
# ifdef __NV_CL_C_VERSION
// flush shuffled data
SCRATCHPAD_CHUNK_GLOBAL = *scratchpad_line;
idx0 = c[0] & MASK;
idx0 = as_uint2(c[0]).s0 & MASK;
idxS = idx0 & 0x30;
*scratchpad_line = SCRATCHPAD_CHUNK_GLOBAL;
# else
idx0 = c[0] & MASK;
idx0 = as_uint2(c[0]).s0 & MASK;
# endif
#else
b_x[0] ^= ((uint4 *)c)[0];
SCRATCHPAD_CHUNK(0) = b_x[0];
idx0 = c[0] & MASK;
idx0 = as_uint2(c[0]).s0 & MASK;
#endif
uint4 tmp;
tmp = SCRATCHPAD_CHUNK(0);
Expand Down Expand Up @@ -755,7 +755,7 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states
#endif

((uint4 *)a)[0] ^= tmp;

// cryptonight_monero_v8
#if (ALGO == 11)
# if defined(__NV_CL_C_VERSION)
Expand All @@ -765,22 +765,22 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states
b_x[1] = b_x[0];
#endif
b_x[0] = ((uint4 *)c)[0];
idx0 = a[0] & MASK;
idx0 = as_uint2(a[0]).s0 & MASK;

// cryptonight_heavy || cryptonight_bittube2
#if (ALGO == 4 || ALGO == 10)
long n = *((__global long*)(Scratchpad + (IDX((idx0) >> 4))));
int d = ((__global int*)(Scratchpad + (IDX((idx0) >> 4))))[2];
long q = fast_div_heavy(n, d | 0x5);
*((__global long*)(Scratchpad + (IDX((idx0) >> 4)))) = n ^ q;
idx0 = (d ^ q) & MASK;
idx0 = (d ^ as_int2(q).s0) & MASK;
// cryptonight_haven
#elif (ALGO == 9)
long n = *((__global long*)(Scratchpad + (IDX((idx0) >> 4))));
int d = ((__global int*)(Scratchpad + (IDX((idx0) >> 4))))[2];
long q = fast_div_heavy(n, d | 0x5);
*((__global long*)(Scratchpad + (IDX((idx0) >> 4)))) = n ^ q;
idx0 = ((~d) ^ q) & MASK;
idx0 = ((~d) ^ as_int2(q).s0) & MASK;
#endif

}
Expand Down Expand Up @@ -815,7 +815,7 @@ __kernel void JOIN(cn2,ALGO) (__global uint4 *Scratchpad, __global ulong *states
__local uint4 xin1[8][8];
__local uint4 xin2[8][8];
#endif

#if(COMP_MODE==1)
// do not use early return here
if(gIdx < Threads)
Expand Down Expand Up @@ -1238,4 +1238,4 @@ __kernel void Groestl(__global ulong *states, __global uint *BranchBuf, __global
}
}

)==="
)==="