mirror of
https://github.com/augustin64/projet-tipe
synced 2025-04-22 05:23:53 +02:00
Check device memory block size
& add pretty-prints & remove some warnings
This commit is contained in:
parent
76f17371de
commit
383d3bebfd
@ -55,7 +55,7 @@ void* train_thread(void* parameters) {
|
||||
maxi = indice_max(network->input[network->size-1][0][0], 10);
|
||||
if (maxi == -1) {
|
||||
printf("\n");
|
||||
printf_error("Le réseau sature.\n");
|
||||
printf_error((char*)"Le réseau sature.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -224,7 +224,9 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
|
||||
|
||||
elapsed_time = end_time - start_time;
|
||||
printf("Taux d'apprentissage initial: %lf\n", network->learning_rate);
|
||||
printf("Initialisation: %0.2lf s\n\n", elapsed_time);
|
||||
printf("Initialisation: ");
|
||||
printf_time(elapsed_time);
|
||||
printf("\n\n");
|
||||
|
||||
for (int i=0; i < epochs; i++) {
|
||||
|
||||
@ -314,7 +316,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
|
||||
update_weights(network, network);
|
||||
update_bias(network, network);
|
||||
|
||||
printf("\rÉpoque [%d/%d]\tImage [%d/%d]\tAccuracy: "YELLOW"%0.4f%%"RESET, i, epochs, BATCHES*(j+1), nb_images_total, current_accuracy*100);
|
||||
printf("\rÉpoque [%d/%d]\tImage [%d/%d]\tAccuracy: " YELLOW "%0.4f%%" RESET, i, epochs, BATCHES*(j+1), nb_images_total, current_accuracy*100);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
// Il serait intéressant d'utiliser la perte calculée pour
|
||||
@ -324,9 +326,13 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
|
||||
end_time = omp_get_wtime();
|
||||
elapsed_time = end_time - start_time;
|
||||
#ifdef USE_MULTITHREADING
|
||||
printf("\rThreads [%d]\tÉpoque [%d/%d]\tImage [%d/%d]\tAccuracy: " GREEN "%0.4f%%" RESET " \tTemps: %0.2f s\n", nb_threads, i, epochs, nb_images_total, nb_images_total, accuracy*100, elapsed_time);
|
||||
printf("\rThreads [%d]\tÉpoque [%d/%d]\tImage [%d/%d]\tAccuracy: " GREEN "%0.4f%%" RESET " \tTemps: ", nb_threads, i, epochs, nb_images_total, nb_images_total, accuracy*100);
|
||||
printf_time(elapsed_time);
|
||||
printf("\n");
|
||||
#else
|
||||
printf("\rÉpoque [%d/%d]\tImage [%d/%d]\tAccuracy: "GREEN"%0.4f%%"RESET" \tTemps: %0.2f s\n", i, epochs, nb_images_total, nb_images_total, accuracy*100, elapsed_time);
|
||||
printf("\rÉpoque [%d/%d]\tImage [%d/%d]\tAccuracy: " GREEN "%0.4f%%" RESET " \tTemps: ", i, epochs, nb_images_total, nb_images_total, accuracy*100);
|
||||
printf_time(elapsed_time);
|
||||
printf("\n");
|
||||
#endif
|
||||
write_network(out, network);
|
||||
}
|
||||
@ -363,5 +369,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
|
||||
|
||||
end_time = omp_get_wtime();
|
||||
elapsed_time = end_time - algo_start;
|
||||
printf("\nTemps total: %0.1f s\n", elapsed_time);
|
||||
printf("\nTemps total: ");
|
||||
printf_time(elapsed_time);
|
||||
printf("\n");
|
||||
}
|
||||
|
56
src/colors.c
56
src/colors.c
@ -1,4 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "include/colors.h"
|
||||
|
||||
@ -12,4 +13,59 @@ void printf_warning(char* string) {
|
||||
|
||||
void printf_info(char* string) {
|
||||
printf(BOLDBLUE "[ INFO ]" RESET " %s", string);
|
||||
}
|
||||
|
||||
void printf_time(float time) {
|
||||
int hours = time/3600;
|
||||
int minutes = ((int)time %3600)/60;
|
||||
int seconds = ((int)time) %60;
|
||||
int milliseconds = (time - (int)time)*1000;
|
||||
|
||||
if (hours != 0) {
|
||||
printf("%dh %dmn", hours, minutes);
|
||||
} else if (minutes != 0) {
|
||||
printf("%dmn %ds", minutes, seconds);
|
||||
} else if (seconds != 0) {
|
||||
printf("%ds %dms", seconds, milliseconds);
|
||||
} else {
|
||||
printf("%dms", milliseconds);
|
||||
}
|
||||
}
|
||||
|
||||
void printf_memory(size_t size) {
|
||||
size_t gigabytes = size/(1024*1024*1024);
|
||||
size_t megabytes = size/(1024*1024) %1024;
|
||||
size_t kilobytes = size/1024 %1024;
|
||||
size_t bytes = size %1024;
|
||||
|
||||
bool is_null = true;
|
||||
|
||||
if (gigabytes != 0) {
|
||||
printf("%ldGB", gigabytes);
|
||||
is_null = false;
|
||||
}
|
||||
if (megabytes != 0) {
|
||||
if (!is_null) {
|
||||
printf(" ");
|
||||
}
|
||||
printf("%ldMB", megabytes);
|
||||
is_null = false;
|
||||
}
|
||||
if (kilobytes != 0) {
|
||||
if (!is_null) {
|
||||
printf(" ");
|
||||
}
|
||||
printf("%ldkB", kilobytes);
|
||||
is_null = false;
|
||||
}
|
||||
if (bytes != 0) {
|
||||
if (!is_null) {
|
||||
printf(" ");
|
||||
}
|
||||
printf("%ldB", bytes);
|
||||
is_null = false;
|
||||
}
|
||||
if (is_null) {
|
||||
printf("OB");
|
||||
}
|
||||
}
|
@ -21,8 +21,43 @@
|
||||
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
|
||||
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
|
||||
|
||||
#ifdef __CUDACC__
|
||||
extern "C"
|
||||
#endif
|
||||
/*
|
||||
* Affiche le texte demandé, précédé d'un [ERROR] en rouge
|
||||
*/
|
||||
void printf_error(char* string);
|
||||
|
||||
#ifdef __CUDACC__
|
||||
extern "C"
|
||||
#endif
|
||||
/*
|
||||
* Affiche le texte demandé, précédé d'un [WARNING] en orange
|
||||
*/
|
||||
void printf_warning(char* string);
|
||||
|
||||
#ifdef __CUDACC__
|
||||
extern "C"
|
||||
#endif
|
||||
/*
|
||||
* Affiche le texte demandé, précédé d'un [INFO] en bleu
|
||||
*/
|
||||
void printf_info(char* string);
|
||||
|
||||
#ifdef __CUDACC__
|
||||
extern "C"
|
||||
#endif
|
||||
/*
|
||||
* Affiche un timing en heures minutes secondes millisecondes en limitant la précision aux deux unités les plus significatives
|
||||
*/
|
||||
void printf_time(float time);
|
||||
|
||||
#ifdef __CUDACC__
|
||||
extern "C"
|
||||
#endif
|
||||
/*
|
||||
* Affiche une quantité de mémoire de manière humainement lisible
|
||||
*/
|
||||
void printf_memory(size_t size);
|
||||
#endif
|
18
src/utils.c
18
src/utils.c
@ -6,9 +6,11 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "include/utils.h"
|
||||
#include "include/memory_management.h"
|
||||
#include "include/colors.h"
|
||||
|
||||
#include "include/utils.h"
|
||||
|
||||
|
||||
int i_div_up(int a, int b) { // Partie entière supérieure de a/b
|
||||
return ((a % b) != 0) ? (a / b + 1) : (a / b);
|
||||
@ -32,11 +34,21 @@ bool check_cuda_compatibility() {
|
||||
|
||||
for (int i=0; i < nDevices; i++) {
|
||||
cudaGetDeviceProperties(&prop, i);
|
||||
printf(" - %s\n", prop.name);
|
||||
printf(" - %s\n\t - Compute Capability: %d.%d\n\t - Memory available: ", prop.name, prop.major, prop.minor);
|
||||
printf_memory(prop.totalGlobalMem);
|
||||
printf("\n\t - Shared Memory per block: ");
|
||||
printf_memory(prop.sharedMemPerBlock);
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
cudaGetDeviceProperties(&prop, 0);
|
||||
printf("Utilisation du GPU: " BLUE "%s" RESET " (Compute capability: %d.%d)\n\n", prop.name, prop.major, prop.minor);
|
||||
printf("Utilisation du GPU: " BLUE "%s" RESET "\n\n", prop.name);
|
||||
|
||||
if (prop.sharedMemPerBlock != MEMORY_BLOCK) {
|
||||
printf_warning((char*)"La taille des blocs mémoire du GPU et celle utilisée dans le code diffèrent.\n");
|
||||
printf("\tCela peut mener à une utilisation supplémentaire de VRAM.\n");
|
||||
printf("\tChanger MEMORY_BLOCK à %ld dans src/include/memory_management.h\n", prop.sharedMemPerBlock);
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
printf("Pas d'utilisation du GPU\n\n");
|
||||
|
18
src/utils.cu
18
src/utils.cu
@ -6,9 +6,11 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "include/utils.h"
|
||||
#include "include/memory_management.h"
|
||||
#include "include/colors.h"
|
||||
|
||||
#include "include/utils.h"
|
||||
|
||||
|
||||
int i_div_up(int a, int b) { // Partie entière supérieure de a/b
|
||||
return ((a % b) != 0) ? (a / b + 1) : (a / b);
|
||||
@ -32,11 +34,21 @@ bool check_cuda_compatibility() {
|
||||
|
||||
for (int i=0; i < nDevices; i++) {
|
||||
cudaGetDeviceProperties(&prop, i);
|
||||
printf(" - %s\n", prop.name);
|
||||
printf(" - %s\n\t - Compute Capability: %d.%d\n\t - Memory available: ", prop.name, prop.major, prop.minor);
|
||||
printf_memory(prop.totalGlobalMem);
|
||||
printf("\n\t - Shared Memory per block: ");
|
||||
printf_memory(prop.sharedMemPerBlock);
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
cudaGetDeviceProperties(&prop, 0);
|
||||
printf("Utilisation du GPU: " BLUE "%s" RESET " (Compute capability: %d.%d)\n\n", prop.name, prop.major, prop.minor);
|
||||
printf("Utilisation du GPU: " BLUE "%s" RESET "\n\n", prop.name);
|
||||
|
||||
if (prop.sharedMemPerBlock != MEMORY_BLOCK) {
|
||||
printf_warning((char*)"La taille des blocs mémoire du GPU et celle utilisée dans le code diffèrent.\n");
|
||||
printf("\tCela peut mener à une utilisation supplémentaire de VRAM.\n");
|
||||
printf("\tChanger MEMORY_BLOCK à %ld dans src/include/memory_management.h\n", prop.sharedMemPerBlock);
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
printf("Pas d'utilisation du GPU\n\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user