Skip to content

Commit e0e5186

Browse files
authored
Merge pull request #41 from biospb/master
memory leaks fix and other improvements
2 parents 73a14a1 + 7070bbc commit e0e5186

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/main.cu

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include "mining.h"
1818
#include "getopt.h"
1919

20+
21+
std::atomic<uint32_t> found_solutions{0};
22+
2023
typedef std::chrono::high_resolution_clock Time;
2124
typedef std::chrono::duration<double> duration_t;
2225
typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_point_t;
@@ -68,6 +71,7 @@ void submit_new_block(mining_worker_t *worker)
6871
uint32_t buf_count = 1;
6972

7073
uv_write(write_req, tcp, &buf, buf_count, on_write_end);
74+
found_solutions.fetch_add(1, std::memory_order_relaxed);
7175
}
7276

7377
void mine_with_timer(uv_timer_t *timer);
@@ -192,7 +196,7 @@ void log_hashrate(uv_timer_t *timer)
192196
{
193197
printf("gpu%d: %.0f MH/s ", i, device_mining_count[i].load() / eplased.count() / 1000000);
194198
}
195-
printf("\n");
199+
printf("solutions: %u\n", found_solutions.load(std::memory_order_relaxed));
196200
}
197201
}
198202

@@ -332,7 +336,7 @@ int main(int argc, char **argv)
332336

333337
printf("Running gpu-miner version : %s\n", MINER_VERSION);
334338

335-
int gpu_count;
339+
int gpu_count = 0;
336340
cudaGetDeviceCount(&gpu_count);
337341
printf("GPU count: %d\n", gpu_count);
338342
for (int i = 0; i < gpu_count; i++)

src/mining.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "blake3.cu"
55

6+
//#define SHOW_MINING_TIME 1
7+
68
void worker_stream_callback(cudaStream_t stream, cudaError_t status, void *data);
79

810
void start_worker_mining(mining_worker_t *worker)
@@ -12,23 +14,31 @@ void start_worker_mining(mining_worker_t *worker)
1214
reset_worker(worker);
1315
TRY( cudaMemcpyAsync(hasher(worker, false), hasher(worker, true), hasher_len(worker), cudaMemcpyHostToDevice, worker->stream) );
1416

17+
#ifdef SHOW_MINING_TIME
1518
cudaEvent_t startEvent, stopEvent;
1619
TRY( cudaEventCreate(&startEvent) );
1720
TRY( cudaEventCreate(&stopEvent) );
18-
1921
TRY( cudaEventRecord(startEvent, worker->stream) );
22+
#endif
23+
2024
// blake3_hasher_mine<<<worker->grid_size, worker->block_size, 0, worker->stream>>>(worker->device_hasher);
2125
MINER_IMPL(worker)<<<worker->grid_size, worker->block_size, 0, worker->stream>>>(worker->device_hasher.inline_hasher);
2226

27+
#ifdef SHOW_MINING_TIME
2328
TRY( cudaEventRecord(stopEvent, worker->stream) );
29+
#endif
2430

2531
TRY(cudaMemcpyAsync(hasher(worker, true), hasher(worker, false), hasher_len(worker), cudaMemcpyDeviceToHost, worker->stream));
2632

2733
TRY( cudaStreamAddCallback(worker->stream, worker_stream_callback, worker, 0) );
2834

35+
#ifdef SHOW_MINING_TIME
2936
float time;
3037
TRY( cudaEventElapsedTime(&time, startEvent, stopEvent) );
31-
// printf(" === mining time: %f\n", time);
38+
TRY( cudaEventDestroy(&startEvent) );
39+
TRY( cudaEventDestroy(&stopEvent) );
40+
printf(" === mining time: %f\n", time);
41+
#endif
3242
}
3343

3444
#endif // ALEPHIUM_MINING_H

src/template.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ uint32_t sub_template__ref_count(mining_template_t *template_ptr, uint32_t value
3838
void free_template(mining_template_t *template_ptr)
3939
{
4040
uint32_t old_count = sub_template__ref_count(template_ptr, 1);
41-
if (old_count == 0) {
41+
if (old_count == 1) { // fetch_sub returns original value
4242
free_job(template_ptr->job);
4343
free(template_ptr);
4444
}

0 commit comments

Comments
 (0)