Skip to content

Commit

Permalink
fix various memory leaks on algo switch
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Mar 11, 2017
1 parent 0041bf4 commit 61231bc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
8 changes: 8 additions & 0 deletions bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "miner.h"
#include "algos.h"
#include <cuda_runtime.h>

int bench_algo = -1;

Expand Down Expand Up @@ -114,6 +115,13 @@ bool bench_algo_switch_next(int thr_id)
if (algo == ALGO_MJOLLNIR) algo++; // same as heavy
if (algo == ALGO_WHIRLCOIN) algo++; // same as whirlpool
if (algo == ALGO_WHIRLPOOLX) algo++; // disabled
// todo: algo switch from RPC 2.0
if (algo == ALGO_CRYPTOLIGHT) algo++;
if (algo == ALGO_CRYPTONIGHT) algo++;
if (algo == ALGO_WILDKECCAK) algo++;
if (algo == ALGO_JACKPOT) algo++; // to fix
if (algo == ALGO_QUARK) algo++; // to fix
if (algo == ALGO_LBRY && CUDART_VERSION < 7000) algo++;

if (device_sm[dev_id] && device_sm[dev_id] < 300) {
// incompatible SM 2.1 kernels...
Expand Down
7 changes: 7 additions & 0 deletions lyra2/cuda_lyra2Z.cu
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,13 @@ void lyra2Z_cpu_init_sm2(int thr_id, uint32_t threads)
cudaMallocHost(&h_GNonces[thr_id], 2 * sizeof(uint32_t));
}

__host__
void lyra2Z_cpu_free(int thr_id)
{
cudaFree(d_GNonces[thr_id]);
cudaFreeHost(h_GNonces[thr_id]);
}

__host__
uint32_t lyra2Z_getSecNonce(int thr_id, int num)
{
Expand Down
3 changes: 3 additions & 0 deletions lyra2/lyra2Z.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern void blake256_cpu_setBlock_80(uint32_t *pdata);

extern void lyra2Z_cpu_init(int thr_id, uint32_t threads, uint64_t *d_matrix);
extern void lyra2Z_cpu_init_sm2(int thr_id, uint32_t threads);
extern void lyra2Z_cpu_free(int thr_id);
extern uint32_t lyra2Z_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNonce, uint64_t *d_outputHash, bool gtx750ti);

extern void lyra2Z_setTarget(const void *ptarget);
Expand Down Expand Up @@ -158,6 +159,8 @@ extern "C" void free_lyra2Z(int thr_id)
cudaFree(d_hash[thr_id]);
if (device_sm[dev_id] >= 350)
cudaFree(d_matrix[thr_id]);
lyra2Z_cpu_free(thr_id);

init[thr_id] = false;

cudaDeviceSynchronize();
Expand Down
2 changes: 1 addition & 1 deletion x11/veltor.cu
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ extern "C" void free_veltor(int thr_id)
cudaThreadSynchronize();

cudaFree(d_hash[thr_id]);
cudaFree(d_resNonce[thr_id]);

cuda_check_cpu_free(thr_id);
init[thr_id] = false;

cudaDeviceSynchronize();
Expand Down
6 changes: 2 additions & 4 deletions x15/cuda_x15_whirlpool.cu
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,8 @@ void whirlpool512_setBlock_80(void *pdata, const void *ptarget)
__host__
extern void x15_whirlpool_cpu_free(int thr_id)
{
cudaFree(InitVector_RC);
cudaFree(b0);
cudaFree(b7);
cudaFree(d_resNonce[thr_id]);
if (d_resNonce[thr_id])
cudaFree(d_resNonce[thr_id]);
}

__global__
Expand Down

0 comments on commit 61231bc

Please sign in to comment.