From a8fa0b9d1c7fe1702653ba51430c900750c767d6 Mon Sep 17 00:00:00 2001 From: aardvark3 Date: Sat, 8 Jan 2022 21:27:28 +0000 Subject: [PATCH 01/11] fix multi-GPU --- src/Cuda/xpmclient.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Cuda/xpmclient.cpp b/src/Cuda/xpmclient.cpp index eac7b6d..2f860f6 100644 --- a/src/Cuda/xpmclient.cpp +++ b/src/Cuda/xpmclient.cpp @@ -24,6 +24,8 @@ #include "prime.h" #include #include +#include +#include void _blkmk_bin2hex(char *out, void *data, size_t datasz) { unsigned char *datac = (unsigned char *)data; @@ -37,7 +39,7 @@ void _blkmk_bin2hex(char *out, void *data, size_t datasz) { } } - +std::mutex mtx; unsigned gDebug = 0; int gExtensionsNum = 9; int gPrimorial = 19; @@ -378,12 +380,14 @@ void PrimeMiner::Mining(GetBlockTemplateContext* gbp, SubmitContext* submit) { // get work bool reset = false; { + mtx.lock(); while ( !(workTemplate = gbp->get(0, workTemplate, &dataId, &hasChanged)) ) usleep(100); if(workTemplate && hasChanged){ run = true;//ReceivePub(work, worksub); reset = true; } + mtx.unlock(); } if(!run) break; @@ -699,8 +703,9 @@ void PrimeMiner::Mining(GetBlockTemplateContext* gbp, SubmitContext* submit) { BN_bn2mpi(xxx, buffer); work.multiplier[0] = buffer[3]; std::reverse_copy(buffer+4, buffer+4+buffer[3], work.multiplier+1); + mtx.lock(); submit->submitBlock(workTemplate, work, dataId); - + mtx.unlock(); LOG_F(1, "GPU %d found share: %d-ch type %d", mID, chainlength, candi.type+1); if(isblock) LOG_F(1, "GPU %d found BLOCK!", mID); @@ -815,6 +820,11 @@ void initCmdLineOptions(option *options) options[clOptionLast] = {0, 0, 0, 0}; } +void InvokeMining(PrimeMiner* miner, GetBlockTemplateContext* getblock, SubmitContext* submit) +{ + miner->Mining(getblock, submit); +} + int main(int argc, char **argv) { srand(time(0)); blkmk_sha256_impl = sha256; @@ -988,10 +998,16 @@ int main(int argc, char **argv) { } unsigned int sievePerRound = 5; + std::vector threads; for(unsigned i = 0; i < gpus.size(); ++i) { PrimeMiner* miner = new PrimeMiner(i, gpus.size(), sievePerRound, depth, clKernelLSize); miner->Initialize(gpus[i].context, gpus[i].device, modules[i]); - miner->Mining(getblock, submit); + std::thread t(InvokeMining, miner, getblock, submit); + threads.push_back(t); + } + + for (auto& t: threads) { + t.join(); } return 0; From fd9e3279d79f379596b94d18ce7eaf8aad01e9e5 Mon Sep 17 00:00:00 2001 From: aardvark3 Date: Sat, 8 Jan 2022 22:03:14 +0000 Subject: [PATCH 02/11] fix --- src/Cuda/xpmclient.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Cuda/xpmclient.cpp b/src/Cuda/xpmclient.cpp index 2f860f6..a8d73f4 100644 --- a/src/Cuda/xpmclient.cpp +++ b/src/Cuda/xpmclient.cpp @@ -998,16 +998,10 @@ int main(int argc, char **argv) { } unsigned int sievePerRound = 5; - std::vector threads; for(unsigned i = 0; i < gpus.size(); ++i) { PrimeMiner* miner = new PrimeMiner(i, gpus.size(), sievePerRound, depth, clKernelLSize); miner->Initialize(gpus[i].context, gpus[i].device, modules[i]); std::thread t(InvokeMining, miner, getblock, submit); - threads.push_back(t); - } - - for (auto& t: threads) { - t.join(); } return 0; From 96f95453b1c23e209471f60ba1a59af8a9a92822 Mon Sep 17 00:00:00 2001 From: aardvark3 Date: Sun, 9 Jan 2022 13:55:12 +0000 Subject: [PATCH 03/11] fix --- src/Cuda/xpmclient.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Cuda/xpmclient.cpp b/src/Cuda/xpmclient.cpp index a8d73f4..4e993b2 100644 --- a/src/Cuda/xpmclient.cpp +++ b/src/Cuda/xpmclient.cpp @@ -24,7 +24,6 @@ #include "prime.h" #include #include -#include #include void _blkmk_bin2hex(char *out, void *data, size_t datasz) { @@ -822,7 +821,7 @@ void initCmdLineOptions(option *options) void InvokeMining(PrimeMiner* miner, GetBlockTemplateContext* getblock, SubmitContext* submit) { - miner->Mining(getblock, submit); + miner->Mining(getblock, submit); } int main(int argc, char **argv) { @@ -1001,7 +1000,8 @@ int main(int argc, char **argv) { for(unsigned i = 0; i < gpus.size(); ++i) { PrimeMiner* miner = new PrimeMiner(i, gpus.size(), sievePerRound, depth, clKernelLSize); miner->Initialize(gpus[i].context, gpus[i].device, modules[i]); - std::thread t(InvokeMining, miner, getblock, submit); + pthread_t thread; + pthread_create(&thread, 0, InvokeMining, miner, getblock, submit); } return 0; From ea0a23ba45e73ff544a6e574dbf842f610f9a558 Mon Sep 17 00:00:00 2001 From: aardvark3 Date: Sun, 9 Jan 2022 14:23:55 +0000 Subject: [PATCH 04/11] update --- contrib/build.sh | 94 ------------------------------------------ contrib/deploy.sh | 3 +- src/Cuda/xpmclient.cpp | 24 +++++++---- 3 files changed, 16 insertions(+), 105 deletions(-) diff --git a/contrib/build.sh b/contrib/build.sh index 5a6c018..305efb9 100755 --- a/contrib/build.sh +++ b/contrib/build.sh @@ -77,97 +77,3 @@ cp /usr/local/cuda-11.2/lib64/libnvrtc.so.11.2 . cp /usr/local/cuda-11.2/lib64/libnvrtc-builtins.so.11.2 . cd .. tar -czf xpmminer-cuda-$VERSION-linux.tar.gz xpmminer-cuda-$VERSION-linux - -# win64 static build - -# gmp -cd /home/user/build/deps-win32 -tar --lzip -xvf ../gmp-6.1.2.tar.lz -cd gmp-6.1.2 -./configure --host=x86_64-w64-mingw32 --build corei7 --prefix=/home/user/install/x86_64-w64-mingw32 --enable-cxx --enable-static --disable-shared -make -j`nproc` -make install - -# openssl -cd /home/user/build/deps-win32 -tar -xzf ../openssl-1.0.2.tar.gz -cd openssl-1.0.2 -sed -i 's/:.dll.a/ -Wl,--export-all -shared:.dll.a/g' Configure -sed -i 's,.*target already defined.*,$target=$_;,g' Configure -./Configure --cross-compile-prefix="x86_64-w64-mingw32-" mingw64 --prefix=/home/user/install/x86_64-w64-mingw32 shared -make -make install - -# curl -cd /home/user/build/deps-win32 -tar -xzf ../curl-7.68.0.tar.gz -cd curl-7.68.0 -./configure --host=x86_64-w64-mingw32 --prefix=/home/user/install/x86_64-w64-mingw32 -make -j`nproc` -make install - -# jansson -cd /home/user/build/deps-win32 -tar -xzf ../jansson-2.11.tar.gz -cd jansson-2.11 -./configure --host=x86_64-w64-mingw32 --prefix=/home/user/install/x86_64-w64-mingw32 --enable-static --disable-shared -make -j`nproc` -make install - -# CLRX -mkdir $HOME/build/deps-win32/CLRX -cd $HOME/build/deps-win32/CLRX -cmake $HOME/build/CLRX-mirror -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$HOME/build/xpmminer/src/cmake/Toolchain-cross-mingw32-linux.cmake -DCMAKE_INSTALL_PREFIX=$HOME/install/x86_64-w64-mingw32 -make -j`nproc` -make install -rm -f $HOME/install/x86_64-w64-mingw32/lib/libCLRX*.dll* - -# xpmminer -mkdir /home/user/build/xpmminer/x86_64-w64-mingw32 -cd /home/user/build/xpmminer/x86_64-w64-mingw32 -cmake ../src -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_TOOLCHAIN_FILE=../src/cmake/Toolchain-cross-mingw32-linux.cmake \ - -DCMAKE_INSTALL_PREFIX=/home/user/install/x86_64-w64-mingw32 \ - -DSTATIC_BUILD=ON \ - -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-win32 \ - -DOpenCL_INCLUDE_DIR=/usr/local/cuda-win32/include \ - -DOpenCL_LIBRARY=/usr/local/cuda-win32/lib/x64/OpenCL.lib \ - -DBUILDOPENCLMINER=OFF -DBUILDCPUMINER=OFF \ - -DCUDA_INCLUDE_DIRS=/usr/local/cuda-win32/include \ - -DCUDA_DRIVER_LIBRARY=/usr/local/cuda-win32/lib/x64/cuda.lib \ - -DCUDA_nvrtc_LIBRARY=/usr/local/cuda-win32/lib/x64/nvrtc.lib \ - -DOPENSSL_CRYPTO_LIBRARY=/home/user/install/x86_64-w64-mingw32/lib/libcrypto.dll.a \ - -DOPENSSL_SSL_LIBRARY=/home/user/install/x86_64-w64-mingw32/lib/libssl.dll.a -make -j`nproc` -cd Cuda -x86_64-w64-mingw32-strip xpmcuda.exe - -# make Nvidia distr -mkdir xpmminer-cuda-$VERSION-win64 -cd xpmminer-cuda-$VERSION-win64 -cp ../xpmcuda.exe miner.exe -mkdir -p xpm/cuda -cp ../../../src/Cuda/*.cu xpm/cuda/ -cp /usr/lib/gcc/x86_64-w64-mingw32/7.3-posix/libgcc_s_seh-1.dll . -cp /usr/lib/gcc/x86_64-w64-mingw32/7.3-posix/libstdc++-6.dll . -cp /usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll . -cp /usr/local/cuda-win32/bin/nvrtc64_112_0.dll ./ -cp /usr/local/cuda-win32/bin/nvrtc-builtins64_112.dll . -cp /home/user/install/x86_64-w64-mingw32/bin/libcurl-4.dll ./ -cp /home/user/install/x86_64-w64-mingw32/bin/libeay32.dll ./ -echo ".\miner.exe --url appalachians.primecoin.org:9915/api/jsonrpc --user NO --pass NO --wallet yourxpmaddress" > xpmminernv.bat - -cd .. - -zip -9 -r xpmminer-cuda-$VERSION-win64.zip xpmminer-cuda-$VERSION-win64 -# Calculate SHA256 checksum -cd /home/user/build/xpmminer -if [ -f /home/user/build/xpmminer/x86_64-Linux/xpmminer-cpu-$VERSION-linux.tar.gz ]; then -sha256sum /home/user/build/xpmminer/x86_64-Linux/xpmminer-cpu-$VERSION-linux.tar.gz >> xpmminer-$VERSION-sha256.txt -fi -if [ -f /home/user/build/xpmminer/x86_64-Linux/xpmminer-cuda-$VERSION-linux.tar.gz ]; then -sha256sum /home/user/build/xpmminer/x86_64-Linux/xpmminer-cuda-$VERSION-linux.tar.gz >> xpmminer-$VERSION-sha256.txt -fi -if [ -f /home/user/build/xpmminer/x86_64-w64-mingw32/xpmminer-cuda-$VERSION-win64.zip ]; then -sha256sum /home/user/build/xpmminer/x86_64-w64-mingw32/xpmminer-cuda-$VERSION-win64.zip >> xpmminer-$VERSION-sha256.txt -fi \ No newline at end of file diff --git a/contrib/deploy.sh b/contrib/deploy.sh index 64fd24e..45e2c5d 100755 --- a/contrib/deploy.sh +++ b/contrib/deploy.sh @@ -81,5 +81,4 @@ docker exec $CONTAINER /home/user/build/build.sh # Grab artifacts rm -rf distr && mkdir distr && cd distr docker cp $CONTAINER:/home/user/build/xpmminer/x86_64-Linux/xpmminer-cpu-$VERSION-linux.tar.gz . -docker cp $CONTAINER:/home/user/build/xpmminer/x86_64-Linux/xpmminer-cuda-$VERSION-linux.tar.gz . -docker cp $CONTAINER:/home/user/build/xpmminer/x86_64-w64-mingw32/Cuda/xpmminer-cuda-$VERSION-win64.zip . \ No newline at end of file +docker cp $CONTAINER:/home/user/build/xpmminer/x86_64-Linux/xpmminer-cuda-$VERSION-linux.tar.gz . \ No newline at end of file diff --git a/src/Cuda/xpmclient.cpp b/src/Cuda/xpmclient.cpp index 4e993b2..65ed27f 100644 --- a/src/Cuda/xpmclient.cpp +++ b/src/Cuda/xpmclient.cpp @@ -24,7 +24,6 @@ #include "prime.h" #include #include -#include void _blkmk_bin2hex(char *out, void *data, size_t datasz) { unsigned char *datac = (unsigned char *)data; @@ -38,7 +37,7 @@ void _blkmk_bin2hex(char *out, void *data, size_t datasz) { } } -std::mutex mtx; + unsigned gDebug = 0; int gExtensionsNum = 9; int gPrimorial = 19; @@ -819,9 +818,16 @@ void initCmdLineOptions(option *options) options[clOptionLast] = {0, 0, 0, 0}; } -void InvokeMining(PrimeMiner* miner, GetBlockTemplateContext* getblock, SubmitContext* submit) +struct MineContext { + GetBlockTemplateContext *gbp; + SubmitContext *submit; + PrimeMiner* miner; +}; + +void InvokeMining(void *arg) { - miner->Mining(getblock, submit); + MineContext *ctx = (MineContext*)arg; + ctx.iner->Mining(ctx.gbp, tx.submit); } int main(int argc, char **argv) { @@ -905,8 +911,6 @@ int main(int argc, char **argv) { //} //printf("blocktemplate_rwrqwrqw %ld\n", (long int)workTemplate); //printf("block height %d\n", workTemplate->height); - - SubmitContext *submit = new SubmitContext(0, gUrl, gUserName, gPassword); { int np = sizeof(gPrimes)/sizeof(unsigned); @@ -997,11 +1001,13 @@ int main(int argc, char **argv) { } unsigned int sievePerRound = 5; + MineContext *mineCtx = new MineContext[gpus.size()]; for(unsigned i = 0; i < gpus.size(); ++i) { - PrimeMiner* miner = new PrimeMiner(i, gpus.size(), sievePerRound, depth, clKernelLSize); - miner->Initialize(gpus[i].context, gpus[i].device, modules[i]); pthread_t thread; - pthread_create(&thread, 0, InvokeMining, miner, getblock, submit); + mineCtx[i].gbp = &getblock; + mineCtx[i].submit = new SubmitContext(0, gUrl, gUserName, gPassword); + mineCtx[i].miner = new PrimeMiner(i, gpus.size(), sievePerRound, depth, clKernelLSize); + pthread_create(&thread, 0, InvokeMining, &mineCtx[i]); } return 0; From 38fe910e2a60a613f35ac11169869785de80dbc1 Mon Sep 17 00:00:00 2001 From: aardvark3 Date: Sun, 9 Jan 2022 15:04:14 +0000 Subject: [PATCH 05/11] update --- src/Cuda/xpmclient.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Cuda/xpmclient.cpp b/src/Cuda/xpmclient.cpp index 65ed27f..461773a 100644 --- a/src/Cuda/xpmclient.cpp +++ b/src/Cuda/xpmclient.cpp @@ -378,14 +378,12 @@ void PrimeMiner::Mining(GetBlockTemplateContext* gbp, SubmitContext* submit) { // get work bool reset = false; { - mtx.lock(); while ( !(workTemplate = gbp->get(0, workTemplate, &dataId, &hasChanged)) ) usleep(100); if(workTemplate && hasChanged){ run = true;//ReceivePub(work, worksub); reset = true; } - mtx.unlock(); } if(!run) break; @@ -701,9 +699,7 @@ void PrimeMiner::Mining(GetBlockTemplateContext* gbp, SubmitContext* submit) { BN_bn2mpi(xxx, buffer); work.multiplier[0] = buffer[3]; std::reverse_copy(buffer+4, buffer+4+buffer[3], work.multiplier+1); - mtx.lock(); submit->submitBlock(workTemplate, work, dataId); - mtx.unlock(); LOG_F(1, "GPU %d found share: %d-ch type %d", mID, chainlength, candi.type+1); if(isblock) LOG_F(1, "GPU %d found BLOCK!", mID); @@ -824,10 +820,10 @@ struct MineContext { PrimeMiner* miner; }; -void InvokeMining(void *arg) +void* InvokeMining(void *arg) { MineContext *ctx = (MineContext*)arg; - ctx.iner->Mining(ctx.gbp, tx.submit); + ctx->miner->Mining(ctx->gbp, ctx->submit); } int main(int argc, char **argv) { @@ -1004,7 +1000,7 @@ int main(int argc, char **argv) { MineContext *mineCtx = new MineContext[gpus.size()]; for(unsigned i = 0; i < gpus.size(); ++i) { pthread_t thread; - mineCtx[i].gbp = &getblock; + mineCtx[i].gbp = getblock; mineCtx[i].submit = new SubmitContext(0, gUrl, gUserName, gPassword); mineCtx[i].miner = new PrimeMiner(i, gpus.size(), sievePerRound, depth, clKernelLSize); pthread_create(&thread, 0, InvokeMining, &mineCtx[i]); From 5656138e2b3ee146744ec51b8e215f7f37c94d93 Mon Sep 17 00:00:00 2001 From: aardvark3 Date: Sun, 9 Jan 2022 16:04:16 +0000 Subject: [PATCH 06/11] update --- src/Cuda/xpmclient.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Cuda/xpmclient.cpp b/src/Cuda/xpmclient.cpp index 461773a..0367502 100644 --- a/src/Cuda/xpmclient.cpp +++ b/src/Cuda/xpmclient.cpp @@ -24,7 +24,7 @@ #include "prime.h" #include #include - +#include void _blkmk_bin2hex(char *out, void *data, size_t datasz) { unsigned char *datac = (unsigned char *)data; static char hex[] = "0123456789abcdef"; @@ -37,7 +37,7 @@ void _blkmk_bin2hex(char *out, void *data, size_t datasz) { } } - +std::mutex mtx; unsigned gDebug = 0; int gExtensionsNum = 9; int gPrimorial = 19; @@ -246,6 +246,7 @@ void PrimeMiner::FermatDispatch(pipeline_t &fermat, } void PrimeMiner::Mining(GetBlockTemplateContext* gbp, SubmitContext* submit) { + mtx.lock(); cuCtxSetCurrent(_context); time_t starttime = time(0); unsigned int dataId; @@ -287,6 +288,7 @@ void PrimeMiner::Mining(GetBlockTemplateContext* gbp, SubmitContext* submit) { cudaBuffer primeBuf[maxHashPrimorial]; cudaBuffer primeBuf2[maxHashPrimorial]; + printf("----------------------------test print at line 291\n"); CUevent sieveEvent; CUDA_SAFE_CALL(cuEventCreate(&sieveEvent, CU_EVENT_BLOCKING_SYNC)); @@ -998,7 +1000,7 @@ int main(int argc, char **argv) { unsigned int sievePerRound = 5; MineContext *mineCtx = new MineContext[gpus.size()]; - for(unsigned i = 0; i < gpus.size(); ++i) { + for(unsigned i = 0; i < 1; ++i) { pthread_t thread; mineCtx[i].gbp = getblock; mineCtx[i].submit = new SubmitContext(0, gUrl, gUserName, gPassword); From 983ede93f3c956b4bc5ef8342dc3bd856ee1a59b Mon Sep 17 00:00:00 2001 From: aardvark3 Date: Sun, 9 Jan 2022 16:10:24 +0000 Subject: [PATCH 07/11] update --- src/Cuda/xpmclient.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Cuda/xpmclient.cpp b/src/Cuda/xpmclient.cpp index 0367502..4f464c2 100644 --- a/src/Cuda/xpmclient.cpp +++ b/src/Cuda/xpmclient.cpp @@ -1005,6 +1005,7 @@ int main(int argc, char **argv) { mineCtx[i].gbp = getblock; mineCtx[i].submit = new SubmitContext(0, gUrl, gUserName, gPassword); mineCtx[i].miner = new PrimeMiner(i, gpus.size(), sievePerRound, depth, clKernelLSize); + mineCtx[i].miner->Initialize(gpus[i].context, gpus[i].device, modules[i]); pthread_create(&thread, 0, InvokeMining, &mineCtx[i]); } From 499fc8385c6107ce0fd6c6bd43fff624e173f4db Mon Sep 17 00:00:00 2001 From: aardvark3 Date: Sun, 9 Jan 2022 16:12:31 +0000 Subject: [PATCH 08/11] update --- src/Cuda/xpmclient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cuda/xpmclient.cpp b/src/Cuda/xpmclient.cpp index 4f464c2..767f3e7 100644 --- a/src/Cuda/xpmclient.cpp +++ b/src/Cuda/xpmclient.cpp @@ -288,7 +288,7 @@ void PrimeMiner::Mining(GetBlockTemplateContext* gbp, SubmitContext* submit) { cudaBuffer primeBuf[maxHashPrimorial]; cudaBuffer primeBuf2[maxHashPrimorial]; - printf("----------------------------test print at line 291\n"); + printf("-----+----------------------test print at line 291\n"); CUevent sieveEvent; CUDA_SAFE_CALL(cuEventCreate(&sieveEvent, CU_EVENT_BLOCKING_SYNC)); @@ -1000,7 +1000,7 @@ int main(int argc, char **argv) { unsigned int sievePerRound = 5; MineContext *mineCtx = new MineContext[gpus.size()]; - for(unsigned i = 0; i < 1; ++i) { + for(unsigned i = 0; i < gpus.size(); ++i) { pthread_t thread; mineCtx[i].gbp = getblock; mineCtx[i].submit = new SubmitContext(0, gUrl, gUserName, gPassword); From 5691781396b9ab010a78f2783aa0459d27a338f5 Mon Sep 17 00:00:00 2001 From: aardvark3 Date: Sun, 9 Jan 2022 16:46:49 +0000 Subject: [PATCH 09/11] update --- src/Cuda/xpmclient.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Cuda/xpmclient.cpp b/src/Cuda/xpmclient.cpp index 767f3e7..a6ece6c 100644 --- a/src/Cuda/xpmclient.cpp +++ b/src/Cuda/xpmclient.cpp @@ -820,11 +820,14 @@ struct MineContext { GetBlockTemplateContext *gbp; SubmitContext *submit; PrimeMiner* miner; + CUDADeviceInfo *device; + CUmodule *mod; }; void* InvokeMining(void *arg) { MineContext *ctx = (MineContext*)arg; + ctx->miner->Initialize(ctx->device->context, ctx->device->device, *(ctx->mod)); ctx->miner->Mining(ctx->gbp, ctx->submit); } @@ -898,8 +901,8 @@ int main(int argc, char **argv) { exit(1); } printf("block sum is %d\n", gThreadsNum); - GetBlockTemplateContext* getblock = new GetBlockTemplateContext(0, gUrl, gUserName, gPassword, gWallet, 4, gThreadsNum, extraNonce); - getblock->run(); + GetBlockTemplateContext getblock(0, gUrl, gUserName, gPassword, gWallet, 4, gThreadsNum, extraNonce); + getblock.run(); blktemplate_t *workTemplate = 0; unsigned int dataId; bool hasChanged; @@ -1002,10 +1005,11 @@ int main(int argc, char **argv) { MineContext *mineCtx = new MineContext[gpus.size()]; for(unsigned i = 0; i < gpus.size(); ++i) { pthread_t thread; - mineCtx[i].gbp = getblock; + mineCtx[i].gbp = &getblock; mineCtx[i].submit = new SubmitContext(0, gUrl, gUserName, gPassword); mineCtx[i].miner = new PrimeMiner(i, gpus.size(), sievePerRound, depth, clKernelLSize); - mineCtx[i].miner->Initialize(gpus[i].context, gpus[i].device, modules[i]); + mineCtx[i].device = &gpus[i]; + mineCtx[i].mod = &modules[i]; pthread_create(&thread, 0, InvokeMining, &mineCtx[i]); } From 929849cad7e1b1329bea13d50ede24f2aad85dc2 Mon Sep 17 00:00:00 2001 From: aardvark3 Date: Sun, 9 Jan 2022 19:55:17 +0000 Subject: [PATCH 10/11] update --- contrib/build.sh | 95 ++++++++++++++++++++++++++++++++++++++++++ contrib/deploy.sh | 4 +- src/Cuda/xpmclient.cpp | 8 ++-- 3 files changed, 102 insertions(+), 5 deletions(-) diff --git a/contrib/build.sh b/contrib/build.sh index 305efb9..2246b71 100755 --- a/contrib/build.sh +++ b/contrib/build.sh @@ -77,3 +77,98 @@ cp /usr/local/cuda-11.2/lib64/libnvrtc.so.11.2 . cp /usr/local/cuda-11.2/lib64/libnvrtc-builtins.so.11.2 . cd .. tar -czf xpmminer-cuda-$VERSION-linux.tar.gz xpmminer-cuda-$VERSION-linux + + +# win64 static build + +# gmp +cd /home/user/build/deps-win32 +tar --lzip -xvf ../gmp-6.1.2.tar.lz +cd gmp-6.1.2 +./configure --host=x86_64-w64-mingw32 --build corei7 --prefix=/home/user/install/x86_64-w64-mingw32 --enable-cxx --enable-static --disable-shared +make -j`nproc` +make install + +# openssl +cd /home/user/build/deps-win32 +tar -xzf ../openssl-1.0.2.tar.gz +cd openssl-1.0.2 +sed -i 's/:.dll.a/ -Wl,--export-all -shared:.dll.a/g' Configure +sed -i 's,.*target already defined.*,$target=$_;,g' Configure +./Configure --cross-compile-prefix="x86_64-w64-mingw32-" mingw64 --prefix=/home/user/install/x86_64-w64-mingw32 shared +make +make install + +# curl +cd /home/user/build/deps-win32 +tar -xzf ../curl-7.68.0.tar.gz +cd curl-7.68.0 +./configure --host=x86_64-w64-mingw32 --prefix=/home/user/install/x86_64-w64-mingw32 +make -j`nproc` +make install + +# jansson +cd /home/user/build/deps-win32 +tar -xzf ../jansson-2.11.tar.gz +cd jansson-2.11 +./configure --host=x86_64-w64-mingw32 --prefix=/home/user/install/x86_64-w64-mingw32 --enable-static --disable-shared +make -j`nproc` +make install + +# CLRX +mkdir $HOME/build/deps-win32/CLRX +cd $HOME/build/deps-win32/CLRX +cmake $HOME/build/CLRX-mirror -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$HOME/build/xpmminer/src/cmake/Toolchain-cross-mingw32-linux.cmake -DCMAKE_INSTALL_PREFIX=$HOME/install/x86_64-w64-mingw32 +make -j`nproc` +make install +rm -f $HOME/install/x86_64-w64-mingw32/lib/libCLRX*.dll* + +# xpmminer +mkdir /home/user/build/xpmminer/x86_64-w64-mingw32 +cd /home/user/build/xpmminer/x86_64-w64-mingw32 +cmake ../src -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_TOOLCHAIN_FILE=../src/cmake/Toolchain-cross-mingw32-linux.cmake \ + -DCMAKE_INSTALL_PREFIX=/home/user/install/x86_64-w64-mingw32 \ + -DSTATIC_BUILD=ON \ + -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-win32 \ + -DOpenCL_INCLUDE_DIR=/usr/local/cuda-win32/include \ + -DOpenCL_LIBRARY=/usr/local/cuda-win32/lib/x64/OpenCL.lib \ + -DBUILDOPENCLMINER=OFF -DBUILDCPUMINER=OFF \ + -DCUDA_INCLUDE_DIRS=/usr/local/cuda-win32/include \ + -DCUDA_DRIVER_LIBRARY=/usr/local/cuda-win32/lib/x64/cuda.lib \ + -DCUDA_nvrtc_LIBRARY=/usr/local/cuda-win32/lib/x64/nvrtc.lib \ + -DOPENSSL_CRYPTO_LIBRARY=/home/user/install/x86_64-w64-mingw32/lib/libcrypto.dll.a \ + -DOPENSSL_SSL_LIBRARY=/home/user/install/x86_64-w64-mingw32/lib/libssl.dll.a +make -j`nproc` +cd Cuda +x86_64-w64-mingw32-strip xpmcuda.exe + +# make Nvidia distr +mkdir xpmminer-cuda-$VERSION-win64 +cd xpmminer-cuda-$VERSION-win64 +cp ../xpmcuda.exe miner.exe +mkdir -p xpm/cuda +cp ../../../src/Cuda/*.cu xpm/cuda/ +cp /usr/lib/gcc/x86_64-w64-mingw32/7.3-posix/libgcc_s_seh-1.dll . +cp /usr/lib/gcc/x86_64-w64-mingw32/7.3-posix/libstdc++-6.dll . +cp /usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll . +cp /usr/local/cuda-win32/bin/nvrtc64_112_0.dll ./ +cp /usr/local/cuda-win32/bin/nvrtc-builtins64_112.dll . +cp /home/user/install/x86_64-w64-mingw32/bin/libcurl-4.dll ./ +cp /home/user/install/x86_64-w64-mingw32/bin/libeay32.dll ./ +echo ".\miner.exe --url appalachians.primecoin.org:9915/api/jsonrpc --user NO --pass NO --wallet yourxpmaddress" > xpmminernv.bat + +cd .. + +zip -9 -r xpmminer-cuda-$VERSION-win64.zip xpmminer-cuda-$VERSION-win64 +# Calculate SHA256 checksum +cd /home/user/build/xpmminer +if [ -f /home/user/build/xpmminer/x86_64-Linux/xpmminer-cpu-$VERSION-linux.tar.gz ]; then +sha256sum /home/user/build/xpmminer/x86_64-Linux/xpmminer-cpu-$VERSION-linux.tar.gz >> xpmminer-$VERSION-sha256.txt +fi +if [ -f /home/user/build/xpmminer/x86_64-Linux/xpmminer-cuda-$VERSION-linux.tar.gz ]; then +sha256sum /home/user/build/xpmminer/x86_64-Linux/xpmminer-cuda-$VERSION-linux.tar.gz >> xpmminer-$VERSION-sha256.txt +fi +if [ -f /home/user/build/xpmminer/x86_64-w64-mingw32/xpmminer-cuda-$VERSION-win64.zip ]; then +sha256sum /home/user/build/xpmminer/x86_64-w64-mingw32/xpmminer-cuda-$VERSION-win64.zip >> xpmminer-$VERSION-sha256.txt +fi \ No newline at end of file diff --git a/contrib/deploy.sh b/contrib/deploy.sh index 45e2c5d..da376f1 100755 --- a/contrib/deploy.sh +++ b/contrib/deploy.sh @@ -81,4 +81,6 @@ docker exec $CONTAINER /home/user/build/build.sh # Grab artifacts rm -rf distr && mkdir distr && cd distr docker cp $CONTAINER:/home/user/build/xpmminer/x86_64-Linux/xpmminer-cpu-$VERSION-linux.tar.gz . -docker cp $CONTAINER:/home/user/build/xpmminer/x86_64-Linux/xpmminer-cuda-$VERSION-linux.tar.gz . \ No newline at end of file +docker cp $CONTAINER:/home/user/build/xpmminer/x86_64-Linux/xpmminer-cuda-$VERSION-linux.tar.gz . +docker cp $CONTAINER:/home/user/build/xpmminer/x86_64-Linux/xpmminer-cuda-$VERSION-linux.tar.gz . +docker cp $CONTAINER:/home/user/build/xpmminer/x86_64-w64-mingw32/Cuda/xpmminer-cuda-$VERSION-win64.zip . \ No newline at end of file diff --git a/src/Cuda/xpmclient.cpp b/src/Cuda/xpmclient.cpp index a6ece6c..14a3886 100644 --- a/src/Cuda/xpmclient.cpp +++ b/src/Cuda/xpmclient.cpp @@ -24,7 +24,8 @@ #include "prime.h" #include #include -#include +#include + void _blkmk_bin2hex(char *out, void *data, size_t datasz) { unsigned char *datac = (unsigned char *)data; static char hex[] = "0123456789abcdef"; @@ -37,7 +38,7 @@ void _blkmk_bin2hex(char *out, void *data, size_t datasz) { } } -std::mutex mtx; + unsigned gDebug = 0; int gExtensionsNum = 9; int gPrimorial = 19; @@ -246,7 +247,6 @@ void PrimeMiner::FermatDispatch(pipeline_t &fermat, } void PrimeMiner::Mining(GetBlockTemplateContext* gbp, SubmitContext* submit) { - mtx.lock(); cuCtxSetCurrent(_context); time_t starttime = time(0); unsigned int dataId; @@ -934,7 +934,7 @@ int main(int argc, char **argv) { std::map mDeviceMap; std::map mDeviceMapRev; - for (unsigned i = 0; i < devicesNum; i++) { + for (unsigned i = 0; i < 1; i++) { char name[128]; CUDADeviceInfo info; mDeviceMap[i] = gpus.size(); From 867108f21037adfe02bef729e6bc4b9011d69196 Mon Sep 17 00:00:00 2001 From: aardvark3 Date: Sun, 9 Jan 2022 19:55:56 +0000 Subject: [PATCH 11/11] update --- contrib/build.sh | 1 - contrib/deploy.sh | 1 - 2 files changed, 2 deletions(-) diff --git a/contrib/build.sh b/contrib/build.sh index 2246b71..5a6c018 100755 --- a/contrib/build.sh +++ b/contrib/build.sh @@ -78,7 +78,6 @@ cp /usr/local/cuda-11.2/lib64/libnvrtc-builtins.so.11.2 . cd .. tar -czf xpmminer-cuda-$VERSION-linux.tar.gz xpmminer-cuda-$VERSION-linux - # win64 static build # gmp diff --git a/contrib/deploy.sh b/contrib/deploy.sh index da376f1..64fd24e 100755 --- a/contrib/deploy.sh +++ b/contrib/deploy.sh @@ -82,5 +82,4 @@ docker exec $CONTAINER /home/user/build/build.sh rm -rf distr && mkdir distr && cd distr docker cp $CONTAINER:/home/user/build/xpmminer/x86_64-Linux/xpmminer-cpu-$VERSION-linux.tar.gz . docker cp $CONTAINER:/home/user/build/xpmminer/x86_64-Linux/xpmminer-cuda-$VERSION-linux.tar.gz . -docker cp $CONTAINER:/home/user/build/xpmminer/x86_64-Linux/xpmminer-cuda-$VERSION-linux.tar.gz . docker cp $CONTAINER:/home/user/build/xpmminer/x86_64-w64-mingw32/Cuda/xpmminer-cuda-$VERSION-win64.zip . \ No newline at end of file