From 94c14cedba39ad40f72dc029fe6325b5f26985d1 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sat, 20 May 2023 22:45:40 +0200 Subject: [PATCH] cnn/config: add FREE_ALL_OPT --- src/cnn/free.c | 2 +- src/cnn/include/config.h | 30 ++++++++++++++++++++---------- src/common/memory_management.c | 1 + src/common/memory_management.cu | 1 + 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/cnn/free.c b/src/cnn/free.c index 09bae9e..f3faec1 100644 --- a/src/cnn/free.c +++ b/src/cnn/free.c @@ -174,7 +174,7 @@ void free_network_creation(Network* network) { } void free_network(Network* network) { - #if defined(USE_CUDA) || defined(TEST_MEMORY_MANAGEMENT) + #if (defined(USE_CUDA) || defined(TEST_MEMORY_MANAGEMENT)) && defined(FREE_ALL_OPT) // Supprimer toute la mémoire allouée avec nalloc directement // Il n'y a alors plus besoin de parcourir tout le réseau, // mais il faut que TOUTE la mémoire du réseau ait été allouée de cette manière diff --git a/src/cnn/include/config.h b/src/cnn/include/config.h index 89789c1..df9d89e 100644 --- a/src/cnn/include/config.h +++ b/src/cnn/include/config.h @@ -2,7 +2,7 @@ #define DEF_CONFIG_H -//* Paramètres d'entraînement +//** Paramètres d'entraînement #define EPOCHS 10 // Nombre d'époques par défaut (itérations sur toutes les images) #define BATCHES 32 // Nombre d'images à voir avant de mettre le réseau à jour #define LEARNING_RATE 3e-4 // Taux d'apprentissage @@ -25,14 +25,6 @@ //#define ADAM_CNN_BIAS -//* Paramètre d'optimisation pour un dataset Jpeg -// keep images in ram e.g re-read and decompress each time -// Enabling this will lead to a large amount of ram used while economizing not that -// much computing power -// Note: 50States10K dataset is 90Go once decompressed, use with caution -//#define STORE_IMAGES_TO_RAM - - //* Limite du réseau // Des valeurs trop grandes dans le réseau risqueraient de provoquer des overflows notamment. // On utilise donc la méthode gradient_clipping, @@ -40,11 +32,29 @@ // https://arxiv.org/pdf/1905.11881.pdf #define NETWORK_CLIP_VALUE 300 -//* Paramètres CUDA + +//** Paramètres CUDA // Le produit des 3 dimensions doit être au maximum 1024 (atteignable avec 8*8*16) // Le réduire permet d'éviter des erreurs "Out of memory" ou "too many resources requested" au lancement des Kernel #define BLOCKSIZE_x 8 #define BLOCKSIZE_y 8 #define BLOCKSIZE_z 8 + +//** Paramètres d'optimisation +//* Paramètre d'optimisation pour un dataset Jpeg +// keep images in ram e.g re-read and decompress each time +// Enabling this will lead to a large amount of ram used while economizing not that +// much computing power +// Note: 50States10K dataset is 90Go once decompressed, use with caution +//#define STORE_IMAGES_TO_RAM + +//* Optimisation de libération de la mémoire pour de larges réseaux +// En utilisant CUDA, de larges réseaux créés dans src/common/memory_management.cu +// peuvent prendre jusqu'à plusieurs heures pour être libérés +// Une optimisation consiste alors à considérer que seul le réseau est dans cet emplacement de mémoire. +// La libération d'un réseau entraîne alors la libération de toute la mémoire, ce qui peut poser problème +// dans certaines situations. +#define FREE_ALL_OPT + #endif \ No newline at end of file diff --git a/src/common/memory_management.c b/src/common/memory_management.c index afd59a3..f652126 100644 --- a/src/common/memory_management.c +++ b/src/common/memory_management.c @@ -69,6 +69,7 @@ void free_all_memory() { tail = NULL; #endif + memory = NULL; pthread_mutex_unlock(&memory_lock); } diff --git a/src/common/memory_management.cu b/src/common/memory_management.cu index afd59a3..f652126 100644 --- a/src/common/memory_management.cu +++ b/src/common/memory_management.cu @@ -69,6 +69,7 @@ void free_all_memory() { tail = NULL; #endif + memory = NULL; pthread_mutex_unlock(&memory_lock); }