From 874fb50818326894dbcfa36cac48dc8aae61f3d8 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Mon, 29 Jul 2024 11:39:44 +0200 Subject: [PATCH] ntt/parameters.cuh: take no-throwing-destructors literally. Mere presence of try-catch in destructor was proven to be problematic in Windows DLL context. --- ntt/parameters.cuh | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/ntt/parameters.cuh b/ntt/parameters.cuh index 2a70171..fd13633 100644 --- a/ntt/parameters.cuh +++ b/ntt/parameters.cuh @@ -249,22 +249,21 @@ public: ~NTTParameters() { int current_id; - cudaGetDevice(¤t_id); - - gpu.select(); - gpu.Dfree(partial_twiddles); + if (cudaGetDevice(¤t_id) != cudaSuccess) { + gpu.select(); + (void)cudaFreeAsync(partial_twiddles, gpu); #if !defined(FEATURE_BABY_BEAR) && !defined(FEATURE_GOLDILOCKS) - gpu.Dfree(radix9_twiddles_9); - gpu.Dfree(radix8_twiddles_8); - gpu.Dfree(radix7_twiddles_7); - gpu.Dfree(radix6_twiddles_12); - gpu.Dfree(radix6_twiddles_6); + (void)cudaFreeAsync(radix9_twiddles_9, gpu); + (void)cudaFreeAsync(radix8_twiddles_8, gpu); + (void)cudaFreeAsync(radix7_twiddles_7, gpu); + (void)cudaFreeAsync(radix6_twiddles_12, gpu); + (void)cudaFreeAsync(radix6_twiddles_6, gpu); #endif + (void)cudaFreeAsync(twiddles[1], gpu); - gpu.Dfree(twiddles[1]); - - cudaSetDevice(current_id); + cudaSetDevice(current_id); + } } inline void sync() const { gpu.sync(); }