From 2d4c4a256635fd82c68d043f630ae7adae564a5e Mon Sep 17 00:00:00 2001 From: "wang.guijie" Date: Sun, 6 Nov 2016 11:58:21 +0800 Subject: [PATCH 01/19] fixed mem leak and duplicat free mem --- sia-gpu-miner.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sia-gpu-miner.c b/sia-gpu-miner.c index d1d74e2..1de48b5 100644 --- a/sia-gpu-miner.c +++ b/sia-gpu-miner.c @@ -243,8 +243,17 @@ void selectOCLDevice(cl_platform_id *OCLPlatform, cl_device_id *OCLDevice, cl_ui // Done. Return the platform ID and device ID object desired, free lists, and return. *OCLPlatform = platformids[platformid]; *OCLDevice = deviceids[deviceidx]; + + if (platformids) { + free(platformids); + } + + if (deviceids) { + free(deviceids); + } } + // printPlatformsAndDevices prints out a list of opencl platforms and devices // that were found on the system. void printPlatformsAndDevices() { @@ -302,10 +311,9 @@ void printPlatformsAndDevices() { ret = clGetDeviceInfo(deviceids[j], CL_DEVICE_NAME, 80, str, NULL); if (ret != CL_SUCCESS) { printf("\tError while getting device info.\n"); - free(deviceids); - continue; - } - printf("\tDevice %d: %s\n", j, str); + } else { + printf("\tDevice %d: %s\n", j, str); + } } free(deviceids); } From 390939d29389714df7d8c25b694535e7b45f1ee8 Mon Sep 17 00:00:00 2001 From: "wang.guijie" Date: Sun, 6 Nov 2016 12:10:33 +0800 Subject: [PATCH 02/19] fixed a mem leak --- network.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/network.c b/network.c index 2f6af0d..edacd57 100644 --- a/network.c +++ b/network.c @@ -20,7 +20,9 @@ struct inBuffer { }; // URL strings for receiving and submitting blocks -char *bfw_url, *submit_url; +#define MAX_HOST_LEN (2048) +char bfw_url[MAX_HOST_LEN]; +char submit_url[MAX_HOST_LEN]; // CURL object to connect to siad CURL *curl; @@ -41,8 +43,12 @@ int check_http_response(CURL *curl) { // set_host establishes the hostname and port that siad is on. void set_host(char *host, char *port) { - bfw_url = malloc(21 + strlen(host) + strlen(port)); - submit_url = malloc(20 + strlen(host) + strlen(port)); + size_t host_len = 21 + strlen(host) + strlen(port); + if (host_len >= MAX_HOST_LEN) { + printf("Error: host is over of size, host_len=%zu > MAX_HOST_LEN=%d\n", host_len, MAX_HOST_LEN); + exit(1); + } + sprintf(bfw_url, "%s%s/miner/header", host, port); sprintf(submit_url, "%s%s/miner/header", host, port); } From 37e18704d52c36350d22fdb9bdeccdc0bad78bfc Mon Sep 17 00:00:00 2001 From: "wang.guijie" Date: Sun, 6 Nov 2016 12:12:40 +0800 Subject: [PATCH 03/19] use fprintf instead of printf --- network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network.c b/network.c index edacd57..3ecc468 100644 --- a/network.c +++ b/network.c @@ -45,7 +45,7 @@ int check_http_response(CURL *curl) { void set_host(char *host, char *port) { size_t host_len = 21 + strlen(host) + strlen(port); if (host_len >= MAX_HOST_LEN) { - printf("Error: host is over of size, host_len=%zu > MAX_HOST_LEN=%d\n", host_len, MAX_HOST_LEN); + fprintf(stderr, "Error: host is over of size, host_len=%zu > MAX_HOST_LEN=%d\n", host_len, MAX_HOST_LEN); exit(1); } From 669c8414a4da514bf738c8f8bff5a4323181733f Mon Sep 17 00:00:00 2001 From: "wang.guijie" Date: Mon, 7 Nov 2016 17:19:01 +0800 Subject: [PATCH 04/19] fixed a commented error --- sia-gpu-miner.cl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sia-gpu-miner.cl b/sia-gpu-miner.cl index d38b96b..cec6dd3 100644 --- a/sia-gpu-miner.cl +++ b/sia-gpu-miner.cl @@ -14,7 +14,7 @@ __constant static const uchar 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 } }; -// Target is passed in via headerIn[32 - 29] +// Target is passed in via headerIn[32 - 39] __kernel void nonceGrind(__global ulong *headerIn, __global ulong *nonceOut) { ulong target = headerIn[4]; ulong m[16] = { headerIn[0], headerIn[1], From 79503ad8629c6be3c359134dea901aab35683700 Mon Sep 17 00:00:00 2001 From: "wang.guijie" Date: Mon, 7 Nov 2016 17:25:15 +0800 Subject: [PATCH 05/19] checkout nonceOut more precise --- sia-gpu-miner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sia-gpu-miner.c b/sia-gpu-miner.c index 1de48b5..718c17b 100644 --- a/sia-gpu-miner.c +++ b/sia-gpu-miner.c @@ -141,7 +141,7 @@ double grindNonces(int cycles_per_iter) { if (ret != CL_SUCCESS) { printf("failed to read nonce from buffer: %d\n", ret); exit(1); } - if (nonceOut[0] != 0) { + if (*(uint64_t *)&nonceOut != 0) { // Copy nonce to header. memcpy(blockHeader+32, nonceOut, 8); if (!submit_header(blockHeader)) { From 213d872b86081a9b0d0e4b22206951cc4845e708 Mon Sep 17 00:00:00 2001 From: guijiewang Date: Mon, 7 Nov 2016 20:04:58 +0800 Subject: [PATCH 06/19] print more GPU devices info --- sia-gpu-miner.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/sia-gpu-miner.c b/sia-gpu-miner.c index 718c17b..58c7310 100644 --- a/sia-gpu-miner.c +++ b/sia-gpu-miner.c @@ -314,6 +314,30 @@ void printPlatformsAndDevices() { } else { printf("\tDevice %d: %s\n", j, str); } + + cl_bool isLitlle = CL_TRUE; + ret = clGetDeviceInfo(deviceids[j], CL_DEVICE_ENDIAN_LITTLE, sizeof(isLitlle), &isLitlle, NULL); + if (ret != CL_SUCCESS) { + printf("\tError while getting device CL_DEVICE_ENDIAN_LITTLE.\n"); + } else { + printf("\tDevice %d: CL_DEVICE_ENDIAN_LITTLE = %d\n", j, isLitlle); + } + + size_t bits = 0; + ret = clGetDeviceInfo(deviceids[j], CL_DEVICE_ADDRESS_BITS, sizeof(bits), &bits, NULL); + if (ret != CL_SUCCESS) { + printf("\tError while getting device CL_DEVICE_ADDRESS_BITS.\n"); + } else { + printf("\tDevice %d: CL_DEVICE_ADDRESS_BITS = %zu\n", j, bits); + } + + size_t maxMemSize = 0; + ret = clGetDeviceInfo(deviceids[j], CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(maxMemSize), &maxMemSize, NULL); + if (ret != CL_SUCCESS) { + printf("\tError while getting device CL_DEVICE_MAX_MEM_ALLOC_SIZE.\n"); + } else { + printf("\tDevice %d: CL_DEVICE_MAX_MEM_ALLOC_SIZE = %zu\n", j, maxMemSize); + } } free(deviceids); } From 6e4d82e7dfea4cf35d6aca6b3c743127ddaaee82 Mon Sep 17 00:00:00 2001 From: guijiewang Date: Wed, 9 Nov 2016 21:53:39 +0800 Subject: [PATCH 07/19] print more GPU devies info --- sia-gpu-miner.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sia-gpu-miner.c b/sia-gpu-miner.c index 58c7310..846cade 100644 --- a/sia-gpu-miner.c +++ b/sia-gpu-miner.c @@ -320,7 +320,7 @@ void printPlatformsAndDevices() { if (ret != CL_SUCCESS) { printf("\tError while getting device CL_DEVICE_ENDIAN_LITTLE.\n"); } else { - printf("\tDevice %d: CL_DEVICE_ENDIAN_LITTLE = %d\n", j, isLitlle); + printf("\tDevice %d: isLitlle: %d\n", j, isLitlle); } size_t bits = 0; @@ -328,7 +328,7 @@ void printPlatformsAndDevices() { if (ret != CL_SUCCESS) { printf("\tError while getting device CL_DEVICE_ADDRESS_BITS.\n"); } else { - printf("\tDevice %d: CL_DEVICE_ADDRESS_BITS = %zu\n", j, bits); + printf("\tDevice %d: bits: %zu\n", j, bits); } size_t maxMemSize = 0; @@ -336,7 +336,7 @@ void printPlatformsAndDevices() { if (ret != CL_SUCCESS) { printf("\tError while getting device CL_DEVICE_MAX_MEM_ALLOC_SIZE.\n"); } else { - printf("\tDevice %d: CL_DEVICE_MAX_MEM_ALLOC_SIZE = %zu\n", j, maxMemSize); + printf("\tDevice %d: maxMemSize: %zu\n", j, maxMemSize); } } free(deviceids); From 54fd7dba37f5de53cfe12d31505c9cfb82602bd8 Mon Sep 17 00:00:00 2001 From: guijiewang Date: Wed, 9 Nov 2016 22:54:31 +0800 Subject: [PATCH 08/19] fixed time consume error in APPLE OS --- sia-gpu-miner.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/sia-gpu-miner.c b/sia-gpu-miner.c index 846cade..beeca1d 100644 --- a/sia-gpu-miner.c +++ b/sia-gpu-miner.c @@ -14,6 +14,7 @@ // OpenCL headers are different for Apple. #ifdef __APPLE__ #include +#include #else #include #endif @@ -70,19 +71,27 @@ void quitSignal(int unused) { printf("\nCaught kill signal, quitting...\n"); } +inline uint64_t get_timestamp_in_us() +{ +#ifdef __linux__ + struct timeval now; + gettimeofday(&now, NULL); + return (uint64_t)now.tv_sec * 1000000LL +now.tv_usec; +#elif __APPLE__ + struct timeval now; + gettimeofday(&now, NULL); + return (uint64_t)now.tv_sec * 1000000LL +now.tv_usec; +#else + return clock()/ CLOCKS_PER_SEC * 1000000LL; +#endif + +} + // Given a number of cycles per iter, grind nonces will poll Sia for a block // then do 2^intensity hashes cycles_per_iter times, checking for a successful // hash each time // Returns -1 if it finds a block, otherwise it returns the hash_rate of the GPU double grindNonces(int cycles_per_iter) { - // Start timing this iteration. - #ifdef __linux__ - struct timespec begin, end; - clock_gettime(CLOCK_REALTIME, &begin); - #else - clock_t startTime = clock(); - #endif - uint8_t blockHeader[80]; uint8_t target[32] = {255}; uint8_t nonceOut[8] = {0}; @@ -112,6 +121,9 @@ double grindNonces(int cycles_per_iter) { blockHeader[i + 32] = target[7-i]; } + // Start timing this iteration. + int64_t beginInUs = get_timestamp_in_us(); + // By doing a bunch of low intensity calls, we prevent freezing // By splitting them up inside this function, we also avoid calling // get_block_for_work too often. @@ -153,17 +165,12 @@ double grindNonces(int cycles_per_iter) { } // Get the time elapsed this function. - #ifdef __linux__ - clock_gettime(CLOCK_REALTIME, &end); - double nsElapsed = 1e9 * (double)(end.tv_sec - begin.tv_sec) + (double)(end.tv_nsec - begin.tv_nsec); - double run_time_seconds = nsElapsed * 1e-9; - #else - double run_time_seconds = (double)(clock() - startTime) / CLOCKS_PER_SEC; - #endif - - // Calculate the hash rate of thie iteration. - double hash_rate = cycles_per_iter * global_item_size / (run_time_seconds*1000000); - return hash_rate; + int64_t endInUs = get_timestamp_in_us(); + int64_t run_time_us = endInUs - beginInUs; + + // Calculate the hash rate of thie iteration. + double hash_rate = cycles_per_iter * global_item_size / (double)run_time_us; + return hash_rate; } // selectOCLDevice manages opencl device selection as requested by the command @@ -503,6 +510,7 @@ int main(int argc, char *argv[]) { size_t max_group_size = 0; ret = clGetDeviceInfo(device_id, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), &max_group_size, NULL); if (ret != CL_SUCCESS) { printf("failed to get Device IDs: %d\n", ret); exit(1); } + printf("max_group_size=%zu\n", max_group_size); if (local_item_size > max_group_size) { printf("Selected device cannot handle work groups larger than %zu.\n", local_item_size); printf("Using work groups of size %zu instead.\n", max_group_size); From 2b786a9f76440f98cb99c98a410ff9c29d144dea Mon Sep 17 00:00:00 2001 From: gjwang Date: Thu, 10 Nov 2016 02:27:19 +0800 Subject: [PATCH 09/19] refactor get time function --- sia-gpu-miner.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/sia-gpu-miner.c b/sia-gpu-miner.c index beeca1d..1f2b311 100644 --- a/sia-gpu-miner.c +++ b/sia-gpu-miner.c @@ -73,11 +73,7 @@ void quitSignal(int unused) { inline uint64_t get_timestamp_in_us() { -#ifdef __linux__ - struct timeval now; - gettimeofday(&now, NULL); - return (uint64_t)now.tv_sec * 1000000LL +now.tv_usec; -#elif __APPLE__ +#if defined(__linux__) || defined(__APPLE__) struct timeval now; gettimeofday(&now, NULL); return (uint64_t)now.tv_sec * 1000000LL +now.tv_usec; @@ -510,7 +506,6 @@ int main(int argc, char *argv[]) { size_t max_group_size = 0; ret = clGetDeviceInfo(device_id, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), &max_group_size, NULL); if (ret != CL_SUCCESS) { printf("failed to get Device IDs: %d\n", ret); exit(1); } - printf("max_group_size=%zu\n", max_group_size); if (local_item_size > max_group_size) { printf("Selected device cannot handle work groups larger than %zu.\n", local_item_size); printf("Using work groups of size %zu instead.\n", max_group_size); From 0f8cff8c19e12ed86638c4c06e075d6e6b125807 Mon Sep 17 00:00:00 2001 From: guijiewang Date: Thu, 10 Nov 2016 10:36:04 +0800 Subject: [PATCH 10/19] refortor get time function --- sia-gpu-miner.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sia-gpu-miner.c b/sia-gpu-miner.c index 1f2b311..d5aa8a1 100644 --- a/sia-gpu-miner.c +++ b/sia-gpu-miner.c @@ -76,11 +76,10 @@ inline uint64_t get_timestamp_in_us() #if defined(__linux__) || defined(__APPLE__) struct timeval now; gettimeofday(&now, NULL); - return (uint64_t)now.tv_sec * 1000000LL +now.tv_usec; + return now.tv_sec * 1000000LL + now.tv_usec; #else return clock()/ CLOCKS_PER_SEC * 1000000LL; #endif - } // Given a number of cycles per iter, grind nonces will poll Sia for a block From baeac59310b1825cb78727ebad1d9e0375eebe66 Mon Sep 17 00:00:00 2001 From: guijiewang Date: Thu, 10 Nov 2016 19:54:06 +0800 Subject: [PATCH 11/19] print submit_header response --- network.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/network.c b/network.c index 3ecc468..8a8392e 100644 --- a/network.c +++ b/network.c @@ -53,6 +53,36 @@ void set_host(char *host, char *port) { sprintf(submit_url, "%s%s/miner/header", host, port); } +static void printMem(const uint8_t *mem, size_t size, const char *format, int num_in_line){ + if (format == NULL) { + format = "%02x "; + } + + if (num_in_line == 0) { + num_in_line = 16; + } + + for (int i=0; i Date: Sat, 12 Nov 2016 16:19:31 +0800 Subject: [PATCH 12/19] fixed sleep in mac os --- network.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/network.c b/network.c index 8a8392e..5708bfb 100644 --- a/network.c +++ b/network.c @@ -2,11 +2,13 @@ #include #include -#ifdef __linux__ +#if defined(__linux__) || defined(__APPLE__) #include -#endif +#else #ifdef __WINDOWS__ #include +#define sleep() Sleep() +#endif #endif #include @@ -128,12 +130,7 @@ int get_header_for_work(uint8_t *target, uint8_t *header) { fprintf(stderr, "Failed to get header from %s, curl_easy_perform() failed: %s\n", bfw_url, curl_easy_strerror(res)); fprintf(stderr, "Are you sure that siad is running?\n"); // Pause in order to prevent spamming the console -#ifdef __linux__ sleep(3); // 3 seconds -#endif -#ifdef __WINDOWS__ - Sleep(3000); // 3 seconds -#endif } if (check_http_response(curl)) { From 85e58f60b7a8859dc95630f24a6323e409ada1a1 Mon Sep 17 00:00:00 2001 From: guijiewang Date: Sat, 12 Nov 2016 16:27:44 +0800 Subject: [PATCH 13/19] fixed sleep in Windows os --- network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network.c b/network.c index 5708bfb..6ee79bf 100644 --- a/network.c +++ b/network.c @@ -7,7 +7,7 @@ #else #ifdef __WINDOWS__ #include -#define sleep() Sleep() +#define sleep(seconds) Sleep(seconds*1000) #endif #endif From 466520606957349b9234aa7fc213d3ce4ed9b6a1 Mon Sep 17 00:00:00 2001 From: gjwang Date: Sun, 13 Nov 2016 23:55:22 +0800 Subject: [PATCH 14/19] rename get_timestamp_in_us to getTimestampInUs --- sia-gpu-miner.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sia-gpu-miner.c b/sia-gpu-miner.c index d5aa8a1..37b22cc 100644 --- a/sia-gpu-miner.c +++ b/sia-gpu-miner.c @@ -71,8 +71,7 @@ void quitSignal(int unused) { printf("\nCaught kill signal, quitting...\n"); } -inline uint64_t get_timestamp_in_us() -{ +inline uint64_t getTimestampInUs() { #if defined(__linux__) || defined(__APPLE__) struct timeval now; gettimeofday(&now, NULL); @@ -117,7 +116,7 @@ double grindNonces(int cycles_per_iter) { } // Start timing this iteration. - int64_t beginInUs = get_timestamp_in_us(); + int64_t beginInUs = getTimestampInUs(); // By doing a bunch of low intensity calls, we prevent freezing // By splitting them up inside this function, we also avoid calling @@ -160,7 +159,7 @@ double grindNonces(int cycles_per_iter) { } // Get the time elapsed this function. - int64_t endInUs = get_timestamp_in_us(); + int64_t endInUs = getTimestampInUs(); int64_t run_time_us = endInUs - beginInUs; // Calculate the hash rate of thie iteration. From 7a10556ce430e5d0cbd4455629604bf6f6b833a5 Mon Sep 17 00:00:00 2001 From: gjwang Date: Mon, 14 Nov 2016 00:01:07 +0800 Subject: [PATCH 15/19] reformat: use Tabs for indentation instead of spaces --- network.c | 60 +++++++++++++++---------------- sia-gpu-miner.c | 96 ++++++++++++++++++++++++------------------------- 2 files changed, 78 insertions(+), 78 deletions(-) diff --git a/network.c b/network.c index 6ee79bf..6a47f3e 100644 --- a/network.c +++ b/network.c @@ -45,32 +45,32 @@ int check_http_response(CURL *curl) { // set_host establishes the hostname and port that siad is on. void set_host(char *host, char *port) { - size_t host_len = 21 + strlen(host) + strlen(port); - if (host_len >= MAX_HOST_LEN) { - fprintf(stderr, "Error: host is over of size, host_len=%zu > MAX_HOST_LEN=%d\n", host_len, MAX_HOST_LEN); - exit(1); - } - + size_t host_len = 21 + strlen(host) + strlen(port); + if (host_len >= MAX_HOST_LEN) { + fprintf(stderr, "Error: host is over of size, host_len=%zu > MAX_HOST_LEN=%d\n", host_len, MAX_HOST_LEN); + exit(1); + } + sprintf(bfw_url, "%s%s/miner/header", host, port); sprintf(submit_url, "%s%s/miner/header", host, port); } -static void printMem(const uint8_t *mem, size_t size, const char *format, int num_in_line){ - if (format == NULL) { - format = "%02x "; - } - - if (num_in_line == 0) { - num_in_line = 16; - } - - for (int i=0; i Date: Mon, 14 Nov 2016 00:19:48 +0800 Subject: [PATCH 16/19] reformat printPlatformsAndDevices to more readable --- sia-gpu-miner.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/sia-gpu-miner.c b/sia-gpu-miner.c index 068a356..53aba05 100644 --- a/sia-gpu-miner.c +++ b/sia-gpu-miner.c @@ -311,33 +311,37 @@ void printPlatformsAndDevices() { // Print platform info. ret = clGetDeviceInfo(deviceids[j], CL_DEVICE_NAME, 80, str, NULL); if (ret != CL_SUCCESS) { - printf("\tError while getting device info.\n"); + printf("\tDevice %d: Error while getting device info.\n", j); } else { printf("\tDevice %d: %s\n", j, str); } - cl_bool isLitlle = CL_TRUE; - ret = clGetDeviceInfo(deviceids[j], CL_DEVICE_ENDIAN_LITTLE, sizeof(isLitlle), &isLitlle, NULL); + cl_bool isLittle = CL_TRUE; + ret = clGetDeviceInfo(deviceids[j], CL_DEVICE_ENDIAN_LITTLE, sizeof(isLittle), &isLittle, NULL); if (ret != CL_SUCCESS) { - printf("\tError while getting device CL_DEVICE_ENDIAN_LITTLE.\n"); + printf("\t\t Error while getting device CL_DEVICE_ENDIAN_LITTLE.\n"); } else { - printf("\tDevice %d: isLitlle: %d\n", j, isLitlle); + if (isLittle) { + printf("\t\t Endianness: Little-endian\n"); + } else { + printf("\t\t Endianness: Big-endian\n"); + } } size_t bits = 0; ret = clGetDeviceInfo(deviceids[j], CL_DEVICE_ADDRESS_BITS, sizeof(bits), &bits, NULL); if (ret != CL_SUCCESS) { - printf("\tError while getting device CL_DEVICE_ADDRESS_BITS.\n"); + printf("\t\t Error while getting device CL_DEVICE_ADDRESS_BITS.\n"); } else { - printf("\tDevice %d: bits: %zu\n", j, bits); + printf("\t\t Address space: %zubits\n", bits); } size_t maxMemSize = 0; ret = clGetDeviceInfo(deviceids[j], CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(maxMemSize), &maxMemSize, NULL); if (ret != CL_SUCCESS) { - printf("\tError while getting device CL_DEVICE_MAX_MEM_ALLOC_SIZE.\n"); + printf("\t\t Error while getting device CL_DEVICE_MAX_MEM_ALLOC_SIZE.\n"); } else { - printf("\tDevice %d: maxMemSize: %zu\n", j, maxMemSize); + printf("\t\t MaxMemAllocSize: %zu\n", maxMemSize); } } free(deviceids); From fbf742ab737b86a70bfe65ccae693b355f59e936 Mon Sep 17 00:00:00 2001 From: gjwang Date: Mon, 14 Nov 2016 01:11:23 +0800 Subject: [PATCH 17/19] print submit work response more nicer --- network.c | 1 + 1 file changed, 1 insertion(+) diff --git a/network.c b/network.c index 6a47f3e..fd41959 100644 --- a/network.c +++ b/network.c @@ -172,6 +172,7 @@ int submit_header(uint8_t *header) { } if (inBuf.bytes) { + printf("\n"); printMem(inBuf.bytes, inBuf.len, "%c", INT_MAX); free(inBuf.bytes); From b5448e4a32964b6021a9104b6979afe945b4c9d1 Mon Sep 17 00:00:00 2001 From: guijiewang Date: Mon, 14 Nov 2016 21:29:11 +0800 Subject: [PATCH 18/19] prevent mass requests from miner in case of server error --- network.c | 10 ---------- network.h | 9 +++++++++ sia-gpu-miner.c | 11 +++++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/network.c b/network.c index fd41959..585a41a 100644 --- a/network.c +++ b/network.c @@ -1,16 +1,6 @@ #include #include #include - -#if defined(__linux__) || defined(__APPLE__) -#include -#else -#ifdef __WINDOWS__ -#include -#define sleep(seconds) Sleep(seconds*1000) -#endif -#endif - #include #include "network.h" diff --git a/network.h b/network.h index 3d46d1a..018cb88 100644 --- a/network.h +++ b/network.h @@ -1,5 +1,14 @@ #include +#if defined(__linux__) || defined(__APPLE__) +#include +#else +#ifdef __WINDOWS__ +#include +#define sleep(seconds) Sleep(seconds*1000) +#endif +#endif + void set_host(char *host, char *port); void init_network(); int get_header_for_work(uint8_t *target, uint8_t *header); diff --git a/sia-gpu-miner.c b/sia-gpu-miner.c index 53aba05..cb0ce8e 100644 --- a/sia-gpu-miner.c +++ b/sia-gpu-miner.c @@ -582,11 +582,14 @@ int main(int argc, char *argv[]) { signal(SIGINT, quitSignal); while (!quit) { // Repeat until no block is found. - do { - hash_rate = grindNonces(cycles_per_iter); - } while (hash_rate == -1 && !quit); + hash_rate = grindNonces(cycles_per_iter); + if (quit) { + break; + } - if (!quit) { + if (hash_rate == -1 ) { + sleep(1); + } else { printf("\rMining at %.3f MH/s\t%u blocks mined", hash_rate, blocks_mined); fflush(stdout); } From 8d8af8db1b31f2db007132933ef03402c2d250ea Mon Sep 17 00:00:00 2001 From: gjwang Date: Wed, 16 Nov 2016 01:43:11 +0800 Subject: [PATCH 19/19] fixed get time consume errro in windows os --- sia-gpu-miner.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sia-gpu-miner.c b/sia-gpu-miner.c index cb0ce8e..f1c8f8a 100644 --- a/sia-gpu-miner.c +++ b/sia-gpu-miner.c @@ -75,9 +75,10 @@ inline uint64_t getTimestampInUs() { #if defined(__linux__) || defined(__APPLE__) struct timeval now; gettimeofday(&now, NULL); - return now.tv_sec * 1000000LL + now.tv_usec; + return now.tv_sec * 1000000ULL + now.tv_usec; #else - return clock()/ CLOCKS_PER_SEC * 1000000LL; + //clock() maybe less than CLOCKS_PER_SEC, so must *1000000ULL first + return (clock() * 1000000ULL) / CLOCKS_PER_SEC; #endif }