Skip to content

Commit

Permalink
Merge pull request #6 from amin63moradi/main
Browse files Browse the repository at this point in the history
alert disconnect proxy
  • Loading branch information
mhssamadani authored Mar 12, 2021
2 parents 410b370 + 86f2772 commit f33630d
Show file tree
Hide file tree
Showing 19 changed files with 483 additions and 394 deletions.
14 changes: 7 additions & 7 deletions ErgoOpenCL.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{19C0E2B9-63F8-4C92-B426-8D0F7E4248BC}</ProjectGuid>
<RootNamespace>ErgoOpenCL</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand All @@ -41,13 +41,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
Expand All @@ -70,10 +70,10 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>C:\boost_1_55_0\boost_1_55_0;C:\OpenSSL-Win64\include;E:\Ergo\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\include;$(IncludePath)</IncludePath>
<IncludePath>C:\boost_1_55_0\boost_1_55_0;C:\OpenSSL-Win64\include;F:\Ergo\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>C:\boost_1_55_0\boost_1_55_0;C:\OpenSSL-Win64\include;E:\Ergo\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\include;$(IncludePath)</IncludePath>
<IncludePath>C:\boost_1_55_0\boost_1_55_0;C:\OpenSSL-Win64\include;F:\Ergo\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand All @@ -93,7 +93,7 @@
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>C:\OpenSSL-Win64\lib;E:\Ergo\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\lib;C:\Program Files %28x86%29\AMD APP SDK\3.0\lib\x86_64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>C:\OpenSSL-Win64\lib;F:\Ergo\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\lib;C:\Program Files %28x86%29\AMD APP SDK\3.0\lib\x86_64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>OpenCL.lib;libcurl.lib;libeay32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
Expand Down Expand Up @@ -126,7 +126,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>OpenCL.lib;libcurl.lib;libeay32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\OpenSSL-Win64\lib;E:\Ergo\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\lib;C:\Program Files %28x86%29\AMD APP SDK\3.0\lib\x86_64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>C:\OpenSSL-Win64\lib;F:\Ergo\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\lib;C:\Program Files %28x86%29\AMD APP SDK\3.0\lib\x86_64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
14 changes: 8 additions & 6 deletions MiningKernel.cl
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ __kernel void BlockMiningStep1(global const cl_uint *data, const cl_ulong base,

((cl_ulong *)(aux))[14] = ~((cl_ulong *)(aux))[14];

((cl_ulong *)(aux))[16] = ((cl_ulong *)data)[0];
((cl_ulong *)(aux))[17] = ((cl_ulong *)data)[1];
((cl_ulong *)(aux))[18] = ((cl_ulong *)data)[2];
((cl_ulong *)(aux))[19] = ((cl_ulong *)data)[3];
((cl_ulong *)(aux))[16] = ((global cl_ulong *)data)[0];
((cl_ulong *)(aux))[17] = ((global cl_ulong *)data)[1];
((cl_ulong *)(aux))[18] = ((global cl_ulong *)data)[2];
((cl_ulong *)(aux))[19] = ((global cl_ulong *)data)[3];
((cl_ulong *)(aux))[20] = tmp;
((cl_ulong *)(aux))[21] = 0;
((cl_ulong *)(aux))[22] = 0;
Expand Down Expand Up @@ -114,10 +114,12 @@ __kernel void BlockMiningStep1(global const cl_uint *data, const cl_ulong base,

h3 = h2 % N_LEN;
//--------------------------read hash from lookup
cl_uint tmpL;
#pragma unroll 8
for (int i = 0; i < 8; ++i)
{
reverseBytesInt(hashes[(h3 << 3) + i], r[7 - i]);
tmpL = hashes[(h3 << 3) + i];
reverseBytesInt(tmpL, r[7 - i]);
}
//------------------------------------------------------

Expand All @@ -136,7 +138,7 @@ __kernel void BlockMiningStep1(global const cl_uint *data, const cl_ulong base,
bT[j] = ((uint8_t *)r)[j + 1];
#pragma unroll
for (j = 31; j < 63; ++j)
bT[j] = ((uint8_t *)data)[j - 31];
bT[j] = ((global uint8_t *)data)[j - 31];
#pragma unroll
for (j = 63; j < 71; ++j)
bT[j] = ((uint8_t *)&tmp)[j - 63];
Expand Down
259 changes: 139 additions & 120 deletions PreHashKernel.cl
Original file line number Diff line number Diff line change
@@ -1,155 +1,174 @@

#include "OCLdecs.h"////problem with relative path


__constant uint8_t blake2b_sigma[12][16] = {
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }
};

#pragma OPENCL EXTENSION cl_amd_media_ops : enable
#pragma OPENCL EXTENSION cl_amd_media_ops2 : enable

ulong FAST_ROTL64_LO(const uint2 x, const uint y) { return(as_ulong(amd_bitalign(x, x.s10, 32 - y))); }
ulong FAST_ROTL64_HI(const uint2 x, const uint y) { return(as_ulong(amd_bitalign(x.s10, x, 32 - (y - 32)))); }


//#define rotr64(x, n) (((x) >> (n)) | ((x) << (64 - (n))))
ulong rotr64(const ulong x2, const uint y)
{
uint2 x = as_uint2(x2);
if (y < 32) return(as_ulong(amd_bitalign(x.s10, x, y)));
else return(as_ulong(amd_bitalign(x, x.s10, (y - 32))));
}

#define G(m, r, i, a, b, c, d) do { \
a += b + ((ulong *)m)[blake2b_sigma[r][i]]; \
d = rotr64(d ^ a, 32);\
c += d; \
b = rotr64(b ^ c, 24); \
a += b + ((ulong *)m)[blake2b_sigma[r][i + 1]]; \
d = rotr64(d ^ a, 16); \
c += d; \
b = rotr64(b ^ c, 63); \
} while(0)


#define BLAKE2B_RND(v, r, m) do { \
G(m, r, 0, v[ 0], v[ 4], v[ 8], v[12]); \
G(m, r, 2, v[ 1], v[ 5], v[ 9], v[13]); \
G(m, r, 4, v[ 2], v[ 6], v[10], v[14]); \
G(m, r, 6, v[ 3], v[ 7], v[11], v[15]); \
G(m, r, 8, v[ 0], v[ 5], v[10], v[15]); \
G(m, r, 10, v[ 1], v[ 6], v[11], v[12]); \
G(m, r, 12, v[ 2], v[ 7], v[ 8], v[13]); \
G(m, r, 14, v[ 3], v[ 4], v[ 9], v[14]); \
} while(0)


inline void BlakeCompress(ulong *h, const ulong *m, ulong t, ulong f)
{
ulong v[16];

((ulong8 *)v)[0] = ((ulong8 *)h)[0];
((ulong8 *)v)[1] = (ulong8)(0x6A09E667F3BCC908UL, 0xBB67AE8584CAA73BUL, 0x3C6EF372FE94F82BUL, 0xA54FF53A5F1D36F1UL, 0x510E527FADE682D1UL, 0x9B05688C2B3E6C1FUL, 0x1F83D9ABFB41BD6BUL, 0x5BE0CD19137E2179UL);

v[12] ^= t;
v[14] ^= f;

#pragma unroll
for (int rnd = 0; rnd < 12; ++rnd)
{
BLAKE2B_RND(v, rnd, m);
}

h[0] ^= v[0] ^ v[0 + 8];
h[1] ^= v[1] ^ v[1 + 8];
h[2] ^= v[2] ^ v[2 + 8];
h[3] ^= v[3] ^ v[3 + 8];
h[4] ^= v[4] ^ v[4 + 8];
h[5] ^= v[5] ^ v[5 + 8];
h[6] ^= v[6] ^ v[6 + 8];
h[7] ^= v[7] ^ v[7 + 8];
}


////////////////////////////////////////////////////////////////////////////////
// First iteration of hashes precalculation
////////////////////////////////////////////////////////////////////////////////
__kernel void InitPrehash(
// data: height
const cl_uint h,
// hashes
global cl_uint * hashes
// data: height
const cl_uint h,
// hashes
global cl_uint * hashes
)
{
cl_uint tid =get_local_id(0);
cl_uint tid = get_local_id(0);

// shared memory
cl_uint height = h;
// shared memory
cl_uint height = h;

tid = get_global_id(0);

if (tid < N_LEN)
{
ulong h[8];
ulong b[16];
ulong t = 0;
//====================================================================//
// Initialize context
//====================================================================//
((ulong8 *)h)[0] = (ulong8)(0x6A09E667F3BCC908UL, 0xBB67AE8584CAA73BUL, 0x3C6EF372FE94F82BUL, 0xA54FF53A5F1D36F1UL, 0x510E527FADE682D1UL, 0x9B05688C2B3E6C1FUL, 0x1F83D9ABFB41BD6BUL, 0x5BE0CD19137E2179UL);

tid = get_global_id(0);
h[0] ^= 0x01010020;

if (tid < N_LEN)
{
//====================================================================//
// Hash tid
//====================================================================//

cl_uint j;
((uint *)b)[0] = as_uint(as_uchar4(tid).s3210);

//====================================================================//
// Hash height
//====================================================================//

((uint *)b)[1] = height;

// local memory
// 472 bytes
cl_uint ldata[118];
//====================================================================//
// Hash constant message
//====================================================================//

// 32 * 64 bits = 256 bytes
cl_ulong * aux = (cl_ulong *)ldata;
// (212 + 4) bytes
ctx_t * ctx = (ctx_t *)(ldata + 64);
ulong ctr = 0;

for (int x = 1; x < 16; ++x, ++ctr)
{
((ulong *)b)[x] = as_ulong(as_uchar8(ctr).s76543210);
}

//====================================================================//
// Initialize context
//====================================================================//
//memset(ctx->b, 0, BUF_SIZE_8);
#pragma unroll
for (int am = 0; am < BUF_SIZE_8; am++)
#pragma unroll 1
for (int z = 0; z < 63; ++z)
{
t += 128;
BlakeCompress((ulong *)h, (ulong *)b, t, 0UL);

#pragma unroll
for (int x = 0; x < 16; ++x, ++ctr)
{
ctx->b[am] = 0;
((ulong *)b)[x] = as_ulong(as_uchar8(ctr).s76543210);
}
B2B_IV(ctx->h);

}

t += 128;
BlakeCompress((ulong *)h, (ulong *)b, t, 0UL);

ctx->h[0] ^= 0x01010000 ^ NUM_SIZE_8;
//memset(ctx->t, 0, 16);
ctx->t[0] = 0;
ctx->t[1] = 0;
ctx->c = 0;
((ulong *)b)[0] = as_ulong(as_uchar8(ctr).s76543210);
t += 8;


//====================================================================//
// Hash tid
//====================================================================//
#pragma unroll
for (j = 0; ctx->c < BUF_SIZE_8 && j < INDEX_SIZE_8; ++j)
{
ctx->b[ctx->c++] = ((const uint8_t *)&tid)[INDEX_SIZE_8 - j - 1];
}

//====================================================================//
// Hash height
//====================================================================//
#pragma unroll
for (j = 0; ctx->c < BUF_SIZE_8 && j < HEIGHT_SIZE ; ++j)
{
ctx->b[ctx->c++] = ((const uint8_t *)&height)[j/*HEIGHT_SIZE - j - 1*/];
}

//====================================================================//
// Hash constant message
//====================================================================//
#pragma unroll
for (j = 0; ctx->c < BUF_SIZE_8 && j < CONST_MES_SIZE_8; ++j)
{
ctx->b[ctx->c++]
= (
!((7 - (j & 7)) >> 1)
* ((j >> 3) >> (((~(j & 7)) & 1) << 3))
) & 0xFF;
}


while (j < CONST_MES_SIZE_8)
{
HOST_B2B_H(ctx, aux);

for ( ; ctx->c < BUF_SIZE_8 && j < CONST_MES_SIZE_8; ++j)
{
ctx->b[ctx->c++]
= (
!((7 - (j & 7)) >> 1)
* ((j >> 3) >> (((~(j & 7)) & 1) << 3))
) & 0xFF;
}
}


//====================================================================//
// Finalize hash
//====================================================================//
HOST_B2B_H_LAST(ctx, aux);
#pragma unroll
for (j = 0; j < NUM_SIZE_8; ++j)
{
((uint8_t *)ldata)[NUM_SIZE_8 - j - 1]
= (ctx->h[j >> 3] >> ((j & 7) << 3)) & 0xFF;
}
for (int i = 1; i < 16; ++i) ((ulong *)b)[i] = 0UL;

BlakeCompress((ulong *)h, (ulong *)b, t, 0xFFFFFFFFFFFFFFFFUL);

//====================================================================//
// Dump result to global memory -- BIG ENDIAN
//====================================================================//
//====================================================================//
// Dump result to global memory -- BIG ENDIAN
//====================================================================//
#pragma unroll
for (int i = 0; i < NUM_SIZE_8; ++i)
{
((uint8_t __global *)hashes)[(tid + 1) * NUM_SIZE_8 - i - 1]
= ((uint8_t *)ldata)[i];
}


j = ((cl_ulong *)ldata)[3] < Q3
|| ((cl_ulong *)ldata)[3] == Q3 && (
((cl_ulong *)ldata)[2] < Q2
|| ((cl_ulong *)ldata)[2] == Q2 && (
((cl_ulong *)ldata)[1] < Q1
|| ((cl_ulong *)ldata)[1] == Q1
&& ((cl_ulong *)ldata)[0] < Q0
)
);



#pragma unroll
for (int i = 0; i < NUM_SIZE_8-1; ++i)
{
//((uint8_t global*)hashes)[(tid + 1) * NUM_SIZE_8 - i -1] = ((uint8_t *)ldata)[i];
((uint8_t global*)hashes)[tid * NUM_SIZE_8 +i ] = ((uint8_t *)ldata)[i];
}
// drop
((uint8_t global*)hashes)[tid * NUM_SIZE_8 +31 ] = 0;
for (int i = 0; i < 4; ++i) ((__global ulong *)hashes)[(tid + 1) * 4 - i - 1] = as_ulong(as_uchar8(h[i]).s76543210);

((__global uchar *)hashes)[tid * 32 + 31] = 0;

}

return;
return;
}

Binary file removed Ubuntu/ErgoOpenCL
Binary file not shown.
Loading

0 comments on commit f33630d

Please sign in to comment.