Skip to content

Commit

Permalink
Merge pull request #21 from tontechio/develop
Browse files Browse the repository at this point in the history
New benchmark, new parameter, better messages

- `-G` (gpu-threads) parameter deprecated
- `-F` (boost factor) parameter as replacement for `-G`
- new benchmark for boost factor
- rename the windows release directories
- add timestamp in messages
- display current hashrate at runtime
- docs updates
  • Loading branch information
tontechio authored Nov 3, 2021
2 parents 6e46b63 + 8b0eb40 commit 98fee9c
Show file tree
Hide file tree
Showing 18 changed files with 296 additions and 178 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/win64-pm-pmcuda-lc-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,23 @@ jobs:
- name: Copy compiled binaries with dependencies
run: |
mkdir deploy_dir
mkdir minertools-cuda-windows-x86-64
copy /Y "build\crypto\Release\libcrypto-1_1-x64.dll" "deploy_dir\"
copy /Y "build\crypto\Release\pow-miner.exe" "deploy_dir\"
copy /Y "build\crypto\Release\pow-miner-cuda.exe" "deploy_dir\"
copy /Y "build\lite-client\Release\lite-client.exe" "deploy_dir\"
copy /Y "build\tonlib\Release\tonlib-cuda-cli.exe" "deploy_dir\"
copy /Y "build\crypto\Release\libcrypto-1_1-x64.dll" "minertools-cuda-windows-x86-64\"
copy /Y "build\crypto\Release\pow-miner-cuda.exe" "minertools-cuda-windows-x86-64\"
copy /Y "build\lite-client\Release\lite-client.exe" "minertools-cuda-windows-x86-64\"
copy /Y "build\tonlib\Release\tonlib-cuda-cli.exe" "minertools-cuda-windows-x86-64\"
- name: Compress collected binaries
uses: papeloto/action-zip@v1
with:
files: deploy_dir/
files: minertools-cuda-windows-x86-64/
recursive: false
dest: deploy_dir/minertools-cuda-windows-x86-64.zip
dest: minertools-cuda-windows-x86-64/minertools-cuda-windows-x86-64.zip

- name: Packing binary files to the GITHUB Release Tag
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifacts: deploy_dir\minertools-*
artifacts: minertools-cuda-windows-x86-64\minertools-*
token: ${{ secrets.GITHUB_TOKEN }}
19 changes: 9 additions & 10 deletions .github/workflows/win64-pm-pmopencl-lc-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,24 @@ jobs:
- name: Copy compiled binaries with dependencies
run: |
mkdir deploy_dir
mkdir minertools-opencl-windows-x86-64
copy /Y "build\crypto\Release\libcrypto-1_1-x64.dll" "deploy_dir\"
copy /Y "build\crypto\Release\OpenCL.dll" "deploy_dir\"
copy /Y "build\crypto\Release\pow-miner.exe" "deploy_dir\"
copy /Y "build\crypto\Release\pow-miner-opencl.exe" "deploy_dir\"
copy /Y "build\lite-client\Release\lite-client.exe" "deploy_dir\"
copy /Y "build\tonlib\Release\tonlib-opencl-cli.exe" "deploy_dir\"
copy /Y "build\crypto\Release\libcrypto-1_1-x64.dll" "minertools-opencl-windows-x86-64\"
copy /Y "build\crypto\Release\OpenCL.dll" "minertools-opencl-windows-x86-64\"
copy /Y "build\crypto\Release\pow-miner-opencl.exe" "minertools-opencl-windows-x86-64\"
copy /Y "build\lite-client\Release\lite-client.exe" "minertools-opencl-windows-x86-64\"
copy /Y "build\tonlib\Release\tonlib-opencl-cli.exe" "minertools-opencl-windows-x86-64\"
- name: Compress collected binaries
uses: papeloto/action-zip@v1
with:
files: deploy_dir/
files: minertools-opencl-windows-x86-64/
recursive: false
dest: deploy_dir/minertools-opencl-windows-x86-64.zip
dest: minertools-opencl-windows-x86-64/minertools-opencl-windows-x86-64.zip

- name: Packing binary files to the GITHUB Release Tag
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifacts: deploy_dir\minertools-*
artifacts: minertools-opencl-windows-x86-64\minertools-*
token: ${{ secrets.GITHUB_TOKEN }}
11 changes: 9 additions & 2 deletions crypto/util/Miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,17 @@ td::optional<std::string> Miner::run(const Options &options) {
return {};
}

void Miner::print_stats(td::Timestamp start_at, td::uint64 hashes_computed, td::uint64 hashes_expected) {
auto passed = td::Timestamp::now().at() - start_at.at();
if (passed < 1e-9) {
passed = 1;
}
LOG(INFO) << "[ passed: "<< passed << "s, hashes computed: " << hashes_computed << " (" << static_cast<double>(hashes_computed)/static_cast<double>(hashes_expected)*100 << "%), speed: " << static_cast<double>(hashes_computed) / passed << " hps ]";
};

td::optional<std::string> build_mine_result(int cpu_id, ton::HDataEnv H, const ton::Miner::Options &options,
unsigned char *rdata, uint64_t nonce, uint64_t vcpu, uint32_t expired) {
std::cout << "FOUND! GPU ID: " << options.gpu_id << ", CPU thread: " << cpu_id << ", GPU thread: " << vcpu
<< ", nonce=" << nonce << ", expired=" << expired << std::endl;
LOG(INFO) << "FOUND! GPU ID: " << options.gpu_id << ", nonce=" << nonce << ", expired=" << expired;

// std::cout << cpu_id << ": "<< "rdata[" << vcpu << "]: ";
// for (int i = 0; i < 32; i++) {
Expand Down
8 changes: 7 additions & 1 deletion crypto/util/Miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ class Miner {
td::optional<td::Timestamp> expire_at;
td::int64 max_iterations = std::numeric_limits<td::int64>::max();
std::atomic<td::uint64>* hashes_computed{nullptr};
td::uint64 hashes_expected = 1;
td::CancellationToken token_;
td::Timestamp start_at;
int verbosity;
td::int32 gpu_id;
td::int32 threads;
td::uint32 gpu_threads = 8;
td::uint32 gpu_threads = 16;
td::uint64 factor = 16;
};

static td::optional<std::string> run(const Options& options);

static void print_stats(td::Timestamp start_at, td::uint64 hashes_computed, td::uint64 hashes_expected);
};

class MinerCuda : public Miner {
Expand Down
15 changes: 10 additions & 5 deletions crypto/util/cuda/credits.cu
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ extern "C" int scanhash_credits(int gpu_id, int cpu_id, ton::HDataEnv H, const t
char guard = head.back();

// throughput
td::uint64 throughput = device_intensity(gpu_id, __func__, 1U << 25); // 256*256*64*8
td::uint64 throughput = (td::uint64)((1U << 19) * options.factor);// 256*256*64*8*factor/64
if (options.max_iterations < throughput) {
throughput = options.max_iterations;
}
std::cout << "[ GPU ID: " << gpu_id << ", CPU thread: " << cpu_id << ", GPU threads: " << options.gpu_threads
<< ", throughput: " << throughput << " ]" << std::endl;
LOG(INFO) << "[ GPU ID: " << gpu_id << ", boost factor: " << options.factor << ", throughput: " << throughput << " ]";

// allocate mem
bitcredit_cpu_init(gpu_id, cpu_id, throughput);
Expand All @@ -36,13 +35,14 @@ extern "C" int scanhash_credits(int gpu_id, int cpu_id, ton::HDataEnv H, const t
// std::cout << "data: " << hex_encode(data) << std::endl;
unsigned char input[123], complexity[32];
memcpy(input, data.ubegin(), data.size());
if (bitcredit_setBlockTarget(gpu_id, options.gpu_threads, cpu_id, input, options.complexity.data(), rdata) == false) {
if (!bitcredit_setBlockTarget(gpu_id, options.gpu_threads, cpu_id, input, options.complexity.data(), rdata)) {
return 0;
}

uint32_t expired;
td::int64 i = 0;
for (; i < options.max_iterations; i += throughput) {
td::Timestamp stat_at = td::Timestamp::now();
for (; i < options.max_iterations;) {
expired = (uint32_t)td::Clocks::system() + 900;
HashResult foundNonce = bitcredit_cpu_hash(gpu_id, cpu_id, options.gpu_threads, throughput, i, expired);
if (foundNonce.nonce != UINT64_MAX) {
Expand All @@ -54,6 +54,11 @@ extern "C" int scanhash_credits(int gpu_id, int cpu_id, ton::HDataEnv H, const t
}
return 1;
}
i += throughput;
if (options.verbosity >= 2 && stat_at.is_in_past()) {
ton::Miner::print_stats(options.start_at, i, options.hashes_expected);
stat_at = stat_at.in(5);
}
if (options.token_) {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/util/cuda/cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,5 @@ void cuda_reset_device(int gpu_id, bool *init) {
}

void cudaReportHardwareFailure(int gpu_id, cudaError_t err, const char *func) {
std::cerr << "[ GPU #" << device_map[gpu_id] << ": " << func << " " << cudaGetErrorString(err) << " ]" << std::endl;
LOG(ERROR) << "[ GPU #" << device_map[gpu_id] << ": " << func << " " << cudaGetErrorString(err) << " ]";
}
7 changes: 2 additions & 5 deletions crypto/util/cuda/cuda_credits.cu
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,10 @@ __host__ void bitcredit_cpu_init(uint32_t gpu_id, uint32_t cpu_id, uint64_t thre

__host__ bool bitcredit_setBlockTarget(uint32_t gpu_id, uint32_t gpu_threads, uint32_t cpu_id, unsigned char *data, const void *target,
unsigned char *rdata) {

#ifndef _WIN32
int len = 123, n = 3;
#else

int len = 123;
const int n = 3;
#endif

uint32_t PaddedMessage[16 * n]; // bring balance to the force, 512*3 bits
memset(PaddedMessage, 0, 16 * n * sizeof(uint32_t));
memcpy(PaddedMessage, data, len);
Expand Down
2 changes: 1 addition & 1 deletion crypto/util/cuda/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef unsigned char uchar;
#define MAX_GPUS 16
#define MAX_CPUS 1
#ifndef MAX_GPU_THREADS
#define MAX_GPU_THREADS 1792
#define MAX_GPU_THREADS 16
#endif
extern char *device_name[MAX_GPUS];
extern short device_map[MAX_GPUS];
Expand Down
2 changes: 1 addition & 1 deletion crypto/util/cuda/sha256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ td::optional<std::string> SHA256::run(ton::HDataEnv H, unsigned char *rdata, con

// mine
if (device_name[options.gpu_id] == NULL) {
std::cout << "not found!" << std::endl;
LOG(INFO) << "device not found!";
exit(4);
}
int rc = scanhash_credits(options.gpu_id, cpu_id, H, options, pdata, target, options.max_iterations, rdata);
Expand Down
2 changes: 1 addition & 1 deletion crypto/util/opencl/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ typedef unsigned char uchar;
#define MAX_GPUS 16
#define MAX_CPUS 1
#ifndef MAX_GPU_THREADS
#define MAX_GPU_THREADS 1792
#define MAX_GPU_THREADS 16
#endif

#if !HAVE_DECL_BE32ENC
Expand Down
33 changes: 19 additions & 14 deletions crypto/util/opencl/opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,13 @@ void OpenCL::create_kernel() {
if (ret != CL_SUCCESS) {
size_t blen = 0;
CL_WRAPPER(clGetProgramBuildInfo(program_, devices_[device_idx_], CL_PROGRAM_BUILD_LOG, 0, NULL, &blen));

#ifndef _WIN32
char buffer[blen];
#else

char *buffer = (char *) malloc(blen);
#endif

CL_WRAPPER(clGetProgramBuildInfo(program_, devices_[device_idx_], CL_PROGRAM_BUILD_LOG, blen, &buffer, NULL));

printf("[ OpenCL: ERROR ]\n%s\n", buffer);

#ifdef _WIN32
free(buffer);
#endif

free(buffer);
exit(4);
}

Expand All @@ -104,11 +96,7 @@ void OpenCL::create_kernel() {
void OpenCL::load_objects(uint32_t gpu_id, uint32_t cpu_id, unsigned char *data, const uint8_t *target,
unsigned char *rdata, uint32_t gpu_threads) {

#ifndef _WIN32
int len = 123, n = 3;
#else
static const int len = 123, n = 3;
#endif

uint32_t PaddedMessage[16 * n]; // bring balance to the force, 512*3 bits
memset(PaddedMessage, 0, 16 * n * sizeof(uint32_t));
Expand Down Expand Up @@ -168,6 +156,23 @@ void OpenCL::load_objects(uint32_t gpu_id, uint32_t cpu_id, unsigned char *data,
CL_WRAPPER(clSetKernelArg(kernel_, 8, sizeof(buffer_result_), (void *)&buffer_result_));
}

void OpenCL::release() {
CL_WRAPPER(clReleaseMemObject(buffer_result_));
CL_WRAPPER(clReleaseMemObject(buffer_expired_));
CL_WRAPPER(clReleaseMemObject(buffer_start_nonce_));
CL_WRAPPER(clReleaseMemObject(buffer_threads_));
CL_WRAPPER(clReleaseMemObject(buffer_cpu_id_));
CL_WRAPPER(clReleaseMemObject(buffer_gpu_threads_));
CL_WRAPPER(clReleaseMemObject(buffer_target_));
CL_WRAPPER(clReleaseMemObject(buffer_data_));
CL_WRAPPER(clReleaseMemObject(buffer_rdata_));
CL_WRAPPER(clReleaseCommandQueue(command_queue_));
CL_WRAPPER(clReleaseKernel(kernel_));
CL_WRAPPER(clReleaseProgram(program_));
CL_WRAPPER(clReleaseContext(context_));
CL_WRAPPER(clReleaseDevice(devices_[device_idx_]));
}

HashResult OpenCL::scan_hash(uint cpu_id, uint32_t gpu_threads, td::uint64 threads, td::uint64 start_nonce, uint expired) {
td::uint64 start = (start_nonce / gpu_threads);
cl_ulong result[2] = {UINT64_MAX, UINT64_MAX};
Expand Down
1 change: 1 addition & 0 deletions crypto/util/opencl/opencl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class OpenCL {
void create_kernel();
void load_objects(uint32_t gpu_id, uint32_t cpu_id, unsigned char *data, const uint8_t *target, unsigned char *rdata, uint32_t gpu_threads);
HashResult scan_hash(uint cpu_id, uint32_t gpu_threads, td::uint64 threads, td::uint64 start_nonce, uint expired);
void release();

private:
size_t source_size_;
Expand Down
17 changes: 12 additions & 5 deletions crypto/util/opencl/sha256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,36 @@ td::optional<std::string> SHA256::run(ton::HDataEnv H, unsigned char *rdata, con
// data
td::Slice data = H.as_slice();

td::uint64 throughput = ((td::uint64)options.gpu_threads) * 256 * 256 * 64;
td::uint64 throughput = (td::uint64)((1U << 19) * options.factor);// 256*256*64*8*factor/64
if (options.max_iterations < throughput) {
throughput = options.max_iterations;
}
std::cout << "[ GPU ID: " << options.gpu_id << ", CPU thread: " << cpu_id << ", GPU threads: " << options.gpu_threads
<< ", throughput: " << throughput << " ]" << std::endl;
LOG(INFO) << "[ GPU ID: " << options.gpu_id << ", boost factor: " << options.factor << ", throughput: " << throughput << " ]";

// set data
// set data
//std::cout << "data: " << hex_encode(data) << std::endl;
unsigned char input[123], complexity[32];
memcpy(input, data.ubegin(), data.size());
opencl.load_objects(options.gpu_id, cpu_id, input, options.complexity.data(), rdata, options.gpu_threads);

uint32_t expired;
td::int64 i = 0;
for (; i < options.max_iterations; i += throughput) {
td::Timestamp stat_at = td::Timestamp::now();
for (; i < options.max_iterations;) {
expired = (uint32_t)td::Clocks::system() + 900;
HashResult foundNonce = opencl.scan_hash(cpu_id, options.gpu_threads, throughput, i, expired);
if (foundNonce.nonce != UINT64_MAX) {
if (options.hashes_computed) {
*options.hashes_computed += i + foundNonce.nonce * foundNonce.vcpu;
}
opencl.release();
return ton::build_mine_result(cpu_id, H, options, rdata, foundNonce.nonce, foundNonce.vcpu, expired);
}
i += throughput;
if (options.verbosity >= 2 && stat_at.is_in_past()) {
ton::Miner::print_stats(options.start_at, i, options.hashes_expected);
stat_at = stat_at.in(5);
}
if (options.token_) {
break;
}
Expand All @@ -57,6 +63,7 @@ td::optional<std::string> SHA256::run(ton::HDataEnv H, unsigned char *rdata, con
*options.hashes_computed += i;
}

opencl.release();
return {};
}

Expand Down
Loading

0 comments on commit 98fee9c

Please sign in to comment.