diff --git a/Makefile b/Makefile index c9bfc63..5eebe24 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ cnn: $(BUILDDIR)/cnn-main; $(BUILDDIR)/cnn-main: $(CNN_SRCDIR)/main.c $(BUILDDIR)/cnn_train.o $(BUILDDIR)/cnn_cnn.o $(BUILDDIR)/cnn_creation.o $(BUILDDIR)/cnn_initialisation.o $(BUILDDIR)/cnn_make.o $(BUILDDIR)/cnn_neuron_io.o $(BUILDDIR)/cnn_function.o $(BUILDDIR)/cnn_utils.o $(BUILDDIR)/cnn_free.o $(BUILDDIR)/cnn_convolution.o $(BUILDDIR)/cnn_backpropagation.o $(BUILDDIR)/colors.o $(BUILDDIR)/mnist.o $(CC) $^ -o $@ $(CFLAGS) -$(BUILDDIR)/cnn-main-cuda: $(BUILDDIR)/cnn_main.o $(BUILDDIR)/cnn_train.o $(BUILDDIR)/cnn_cnn.o $(BUILDDIR)/cnn_creation.o $(BUILDDIR)/cnn_initialisation.o $(BUILDDIR)/cnn_make.o $(BUILDDIR)/cnn_neuron_io.o $(BUILDDIR)/cnn_function.o $(BUILDDIR)/cnn_utils.o $(BUILDDIR)/cnn_free.o $(BUILDDIR)/cnn_cuda_convolution.o $(BUILDDIR)/cnn_backpropagation.o $(BUILDDIR)/colors.o $(BUILDDIR)/mnist.o +$(BUILDDIR)/cnn-main-cuda: $(BUILDDIR)/cnn_main.o $(BUILDDIR)/cnn_train.o $(BUILDDIR)/cnn_cnn.o $(BUILDDIR)/cnn_creation.o $(BUILDDIR)/cnn_initialisation.o $(BUILDDIR)/cnn_make.o $(BUILDDIR)/cnn_neuron_io.o $(BUILDDIR)/cnn_function.o $(BUILDDIR)/cnn_utils.o $(BUILDDIR)/cnn_free.o $(BUILDDIR)/cnn_cuda_convolution.o $(BUILDDIR)/cnn_backpropagation.o $(BUILDDIR)/cuda_utils.o $(BUILDDIR)/colors.o $(BUILDDIR)/mnist.o $(NVCC) $(NVCCFLAGS) $^ -o $@ $(BUILDDIR)/cnn_%.o: $(CNN_SRCDIR)/%.c $(CNN_SRCDIR)/include/%.h @@ -86,12 +86,15 @@ endif $(BUILDDIR)/%.o: $(SRCDIR)/%.c $(SRCDIR)/include/%.h $(CC) -c $< -o $@ $(CFLAGS) +$(BUILDDIR)/cuda_%.o: $(SRCDIR)/%.cu $(SRCDIR)/include/%.h + $(NVCC) $(NVCCFLAGS) -c $< -o $@ + # # Tests # run-tests: build-tests $(foreach file, $(wildcard $(TEST_SRCDIR)/*.sh), $(file);) - @echo "$$(for file in build/test-*; do echo $$file; $$file; done)" + @echo "$$(for file in build/test-*; do echo -e \\033[33m#####\\033[0m $$file \\033[33m#####\\033[0m; $$file; done)" build-tests: prepare-tests $(TESTS_OBJ) $(BUILDDIR)/test-cnn_matrix_multiplication $(BUILDDIR)/test-cnn_convolution @@ -107,7 +110,7 @@ build/test-cnn_%: test/cnn_%.c $(CNN_OBJ) $(BUILDDIR)/colors.o $(BUILDDIR)/mnist build/test-mnist_%: test/mnist_%.c $(MNIST_OBJ) $(BUILDDIR)/colors.o $(CC) $^ -o $@ $(CFLAGS) -$(BUILDDIR)/test-cnn_%: test/cnn_%.cu $(BUILDDIR)/cnn_cuda_%.o $(BUILDDIR)/colors.o $(BUILDDIR)/mnist.o +$(BUILDDIR)/test-cnn_%: test/cnn_%.cu $(BUILDDIR)/cnn_cuda_%.o $(BUILDDIR)/cuda_utils.o $(BUILDDIR)/colors.o $(BUILDDIR)/mnist.o ifndef NVCC_INSTALLED @echo "nvcc not found, skipping" else diff --git a/src/cnn/convolution.c b/src/cnn/convolution.c index 1ff87e7..baf7689 100644 --- a/src/cnn/convolution.c +++ b/src/cnn/convolution.c @@ -1,26 +1,11 @@ -/* This file is a copy of src/cnn/convolution.cu */ #include #include #include #include "include/struct.h" - -#define BLOCKSIZE_x 16 -#define BLOCKSIZE_y 8 -#define BLOCKSIZE_z 8 - - #ifdef __CUDACC__ -/* CUDA memcheck */ -#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } -inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) { - if (code != cudaSuccess) { - fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line); - if (abort) exit(code); - } -} -#endif - + #include "../include/utils.h" +#else bool check_cuda_compatibility() { #ifdef __CUDACC__ int nDevices; @@ -40,13 +25,19 @@ bool check_cuda_compatibility() { } cudaGetDeviceProperties(&prop, 0); - printf("Utilisation du GPU: %s (Compute capability: %d.%d)\n\n", prop.name, prop.major, prop.minor); + printf("Utilisation du GPU: " BLUE "%s" RESET " (Compute capability: %d.%d)\n\n", prop.name, prop.major, prop.minor); return true; #else printf("Pas d'utilisation du GPU\n\n"); return false; #endif } +#endif + +#define BLOCKSIZE_x 16 +#define BLOCKSIZE_y 8 +#define BLOCKSIZE_z 8 + void make_convolution_cpu(Kernel_cnn* kernel, float*** input, float*** output, int output_dim) { // c'est le kernel de input @@ -72,9 +63,6 @@ void make_convolution_cpu(Kernel_cnn* kernel, float*** input, float*** output, i } #ifdef __CUDACC__ -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); -} __global__ void make_convolution_kernel(int k_size, int columns, int rows, float*** bias, size_t pitch_bias, float**** w, size_t pitch_w, float*** input, size_t pitch_input, float*** output, size_t pitch_output, int output_dim) { // Équivalents respectifs de i, j et k dans la boucle effectuée par le cpu diff --git a/src/cnn/convolution.cu b/src/cnn/convolution.cu index b944bcb..293c6a2 100644 --- a/src/cnn/convolution.cu +++ b/src/cnn/convolution.cu @@ -3,21 +3,41 @@ #include #include "include/struct.h" +#ifdef __CUDACC__ + #include "../include/utils.h" +#else +bool check_cuda_compatibility() { + #ifdef __CUDACC__ + int nDevices; + cudaDeviceProp prop; + + cudaGetDeviceCount(&nDevices); + if (nDevices == 0) { + printf("Pas d'utilisation du GPU\n\n"); + return false; + } + + printf("GPUs disponibles:\n"); + + for (int i=0; i < nDevices; i++) { + cudaGetDeviceProperties(&prop, i); + printf(" - %s\n", prop.name); + } + + cudaGetDeviceProperties(&prop, 0); + printf("Utilisation du GPU: " BLUE "%s" RESET " (Compute capability: %d.%d)\n\n", prop.name, prop.major, prop.minor); + return true; + #else + printf("Pas d'utilisation du GPU\n\n"); + return false; + #endif +} +#endif #define BLOCKSIZE_x 16 #define BLOCKSIZE_y 8 #define BLOCKSIZE_z 8 -#ifdef __CUDACC__ -/* CUDA memcheck */ -#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } -inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) { - if (code != cudaSuccess) { - fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line); - if (abort) exit(code); - } -} -#endif void make_convolution_cpu(Kernel_cnn* kernel, float*** input, float*** output, int output_dim) { // c'est le kernel de input @@ -43,9 +63,6 @@ void make_convolution_cpu(Kernel_cnn* kernel, float*** input, float*** output, i } #ifdef __CUDACC__ -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); -} __global__ void make_convolution_kernel(int k_size, int columns, int rows, float*** bias, size_t pitch_bias, float**** w, size_t pitch_w, float*** input, size_t pitch_input, float*** output, size_t pitch_output, int output_dim) { // Équivalents respectifs de i, j et k dans la boucle effectuée par le cpu diff --git a/src/cnn/include/convolution.h b/src/cnn/include/convolution.h index 99d8e62..4e0eaf8 100644 --- a/src/cnn/include/convolution.h +++ b/src/cnn/include/convolution.h @@ -6,11 +6,6 @@ void make_convolution_cpu(Kernel_cnn* kernel, float*** input, float*** output, int output_dim); #ifdef __CUDACC__ -/* -* Partie entière supérieure de a/b -*/ -int i_div_up(int a, int b); - /* * Kernel de la convolution sur carte graphique */ diff --git a/src/cnn/include/matrix_multiplication.h b/src/cnn/include/matrix_multiplication.h index 71c3ca1..dab2f35 100644 --- a/src/cnn/include/matrix_multiplication.h +++ b/src/cnn/include/matrix_multiplication.h @@ -7,10 +7,6 @@ #ifdef __CUDACC__ -/* -* Partie entière supérieure de a/b -*/ -int i_div_up(int a, int b); /* * Fonction exécutée par chaque thread lancé dans `matrix_multiplication_device` @@ -23,11 +19,6 @@ __global__ void matrix_mul_kernel(float* Md, float* Nd, float* Pd, int n, int p, void matrix_multiplication_device(float** m1, float** m2, float** result, int n, int p, int q); #endif -/* -* Vérification de la compatibilité CUDA -*/ -bool check_cuda_compatibility(); - /* * Multiplication naïve de matrices sur le CPU (1 seul coeur) */ diff --git a/src/cnn/matrix_multiplication.cu b/src/cnn/matrix_multiplication.cu index 6812c4b..c331343 100644 --- a/src/cnn/matrix_multiplication.cu +++ b/src/cnn/matrix_multiplication.cu @@ -2,27 +2,13 @@ #include #include +#include "../include/colors.h" +#include "../include/utils.h" + #define BLOCKSIZE_x 16 #define BLOCKSIZE_y 16 #ifdef __CUDACC__ -/* CUDA memcheck */ -#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } -inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) { - if (code != cudaSuccess) { - fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line); - if (abort) exit(code); - } -} -#endif - - -#ifdef __CUDACC__ -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); -} - - __global__ void matrix_mul_kernel(float* Md, float* Nd, float* Pd, int n, int p, int q, size_t pitch_m, size_t pitch_n, size_t pitch_p) { // Chaque thread calcule toutes les multiplications utilisant l'élément Nd[tx][ty] int tx = (blockIdx.x*blockDim.x) + threadIdx.x; // Indice de colonne @@ -90,34 +76,6 @@ void matrix_multiplication_device(float** m1, float** m2, float** result, int n, #endif -bool check_cuda_compatibility() { - #ifdef __CUDACC__ - int nDevices; - cudaDeviceProp prop; - - cudaGetDeviceCount(&nDevices); - if (nDevices == 0) { - printf("Pas d'utilisation du GPU\n\n"); - return false; - } - - printf("GPUs disponibles:\n"); - - for (int i=0; i < nDevices; i++) { - cudaGetDeviceProperties(&prop, i); - printf(" - %s\n", prop.name); - } - - cudaGetDeviceProperties(&prop, 0); - printf("Utilisation du GPU: %s (Compute capability: %d.%d)\n\n", prop.name, prop.major, prop.minor); - return true; - #else - printf("Pas d'utilisation du GPU\n\n"); - return false; - #endif -} - - void matrix_multiplication_host(float** m1, float** m2, float** result, int n, int p, int q) { for (int i=0; i < n; i++) { for (int j=0; j < q; j++) { diff --git a/src/include/utils.h b/src/include/utils.h new file mode 100644 index 0000000..2f96a2d --- /dev/null +++ b/src/include/utils.h @@ -0,0 +1,25 @@ +#ifndef DEF_UTILS_CU_H +#define DEF_UTILS_CU_H + +#ifdef __CUDACC__ +/* CUDA memcheck */ +#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); } +inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true) { + if (code != cudaSuccess) { + fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line); + if (abort) exit(code); + } +} +#endif + +/* +* Partie entière supérieure de a/b +*/ +int i_div_up(int a, int b); + +/* +* Vérification de la compatibilité CUDA +*/ +bool check_cuda_compatibility(); + +#endif \ No newline at end of file diff --git a/src/utils.cu b/src/utils.cu new file mode 100644 index 0000000..8998d22 --- /dev/null +++ b/src/utils.cu @@ -0,0 +1,37 @@ +#include +#include + +#include "include/utils.h" +#include "include/colors.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); +} + +bool check_cuda_compatibility() { + #ifdef __CUDACC__ + int nDevices; + cudaDeviceProp prop; + + cudaGetDeviceCount(&nDevices); + if (nDevices == 0) { + printf("Pas d'utilisation du GPU\n\n"); + return false; + } + + printf("GPUs disponibles:\n"); + + for (int i=0; i < nDevices; i++) { + cudaGetDeviceProperties(&prop, i); + printf(" - %s\n", prop.name); + } + + cudaGetDeviceProperties(&prop, 0); + printf("Utilisation du GPU: " BLUE "%s" RESET " (Compute capability: %d.%d)\n\n", prop.name, prop.major, prop.minor); + return true; + #else + printf("Pas d'utilisation du GPU\n\n"); + return false; + #endif +} \ No newline at end of file diff --git a/test/cnn_convolution.cu b/test/cnn_convolution.cu index 1c2259e..d290adc 100644 --- a/test/cnn_convolution.cu +++ b/test/cnn_convolution.cu @@ -7,6 +7,8 @@ #include "../src/cnn/include/convolution.h" #include "../src/cnn/include/struct.h" +#include "../src/include/colors.h" +#include "../src/include/utils.h" float random_float(float low, float high) { @@ -75,39 +77,12 @@ void free_matrix(float*** matrix, int n, int p) { free(matrix); } -bool check_cuda_compatibility() { - #ifdef __CUDACC__ - int nDevices; - cudaDeviceProp prop; - - cudaGetDeviceCount(&nDevices); - if (nDevices == 0) { - printf("Pas d'utilisation du GPU\n\n"); - return false; - } - - printf("GPUs disponibles:\n"); - - for (int i=0; i < nDevices; i++) { - cudaGetDeviceProperties(&prop, i); - printf(" - %s\n", prop.name); - } - - cudaGetDeviceProperties(&prop, 0); - printf("Utilisation du GPU: %s (Compute capability: %d.%d)\n\n", prop.name, prop.major, prop.minor); - return true; - #else - printf("Pas d'utilisation du GPU\n\n"); - return false; - #endif -} - bool check_matrices_equality(float*** m1, float*** m2, int n, int p, int q, int acceptation) { for (int i=0; i < n; i++) { for (int j=0; j < p; j++) { for (int k=0; k < q; k++) { if (fabs(m1[i][j][k] - m2[i][j][k]) > 0.01*acceptation) { - printf("diff %d %d %d: %f val: %f et %f\n", i, j, k, fabs(m1[i][j][k] - m2[i][j][k]), m1[i][j][k], m2[i][j][k]); + printf(RED "diff %d %d %d: %f val: %f et %f\n" RESET, i, j, k, fabs(m1[i][j][k] - m2[i][j][k]), m1[i][j][k], m2[i][j][k]); return false; } } @@ -170,7 +145,7 @@ void run_convolution_test(int input_dim, int output_dim, int rows, int columns) if (!check_matrices_equality(output_gpu, output_cpu, kernel->columns, output_dim, output_dim, kernel->k_size)) {// TODO: change acceptation exit(1); } - printf("OK\n"); + printf(GREEN "OK\n" RESET); free_matrix(kernel->bias, kernel->columns, output_dim); free_matrix(kernel->d_bias, kernel->columns, output_dim); @@ -192,16 +167,16 @@ int main() { printf("Checking CUDA compatibility.\n"); bool cuda_compatible = check_cuda_compatibility(); if (!cuda_compatible) { - printf("CUDA not compatible, skipping tests.\n"); + printf(RED "CUDA not compatible, skipping tests.\n" RESET); return 0; } - printf("OK\n"); + printf(GREEN "OK\n" RESET); srand(time(NULL)); run_convolution_test(20, 15, 30, 40); run_convolution_test(30, 25, 40, 50); - run_convolution_test(200, 10, 40, 50); + run_convolution_test(250, 200, 3, 3); return 0; } \ No newline at end of file diff --git a/test/cnn_matrix_multiplication.cu b/test/cnn_matrix_multiplication.cu index 3f7d875..4f1961e 100644 --- a/test/cnn_matrix_multiplication.cu +++ b/test/cnn_matrix_multiplication.cu @@ -5,6 +5,8 @@ #include #include "../src/cnn/include/matrix_multiplication.h" +#include "../src/include/colors.h" +#include "../src/include/utils.h" float random_float(float low, float high) { @@ -76,30 +78,27 @@ void run_matrices_test(int n, int p, int q) { float** result_gpu = create_empty_matrix(n, q); float** result_cpu = create_empty_matrix(n, q); - printf("(%d,%d)x(%d,%d) Computing on GPU.\n", n, p, p, q); + printf("(%d,%d)x(%d,%d) Data generation complete.\n", n, p, p, q); start = clock(); matrix_multiplication_device(matrix1, matrix2, result_gpu, n, p, q); end = clock(); cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; printf("(%d,%d)x(%d,%d) Time used for GPU: %lf seconds\n", n, p, p, q, cpu_time_used); - printf("OK\n"); - printf("(%d,%d)x(%d,%d) Computing on CPU.\n", n, p, p, q); start = clock(); matrix_multiplication_host(matrix1, matrix2, result_cpu, n, p, q); end = clock(); gpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; printf("(%d,%d)x(%d,%d) Time used for CPU: %lf seconds\n", n, p, p, q, gpu_time_used); - printf("OK\n"); // Vérification de l'égalité des matrices printf("(%d,%d)x(%d,%d) Checking equality.\n", n, p, p, q); if (!check_matrices_equality(result_gpu, result_cpu, n, q, p)) { exit(1); } - printf("OK\n"); + printf(GREEN "OK\n" RESET); // On libère l'espace mémoire alloué for (int i=0; i < n; i++) { @@ -131,7 +130,7 @@ int main() { printf("CUDA not compatible, skipping tests.\n"); return 0; } - printf("OK\n"); + printf(GREEN "OK\n" RESET); srand(time(NULL)); run_matrices_test(200, 1000, 200); diff --git a/test/cnn_neuron_io.c b/test/cnn_neuron_io.c index 78be082..3588e16 100644 --- a/test/cnn_neuron_io.c +++ b/test/cnn_neuron_io.c @@ -7,27 +7,28 @@ #include "../src/cnn/include/neuron_io.h" #include "../src/cnn/include/creation.h" #include "../src/cnn/include/utils.h" +#include "../src/include/colors.h" int main() { printf("Création du réseau\n"); Network* network = create_network_lenet5(0, 0, 3, 2, 32, 1); - printf("OK\n"); + printf(GREEN "OK\n" RESET); printf("Écriture du réseau\n"); - write_network(".test-cache/cnn_neuron_io.bin", network); - printf("OK\n"); + write_network((char*)".test-cache/cnn_neuron_io.bin", network); + printf(GREEN "OK\n" RESET); printf("Vérification de l'accès en lecture\n"); - Network* network2 = read_network(".test-cache/cnn_neuron_io.bin"); - printf("OK\n"); + Network* network2 = read_network((char*)".test-cache/cnn_neuron_io.bin"); + printf(GREEN "OK\n" RESET); printf("Vérification de l'égalité des réseaux\n"); if (! equals_networks(network, network2)) { - printf_error("Les deux réseaux obtenus ne sont pas égaux.\n"); + printf_error(RED "Les deux réseaux obtenus ne sont pas égaux.\n" RESET); exit(1); } - printf("OK\n"); + printf(GREEN "OK\n" RESET); return 0; } \ No newline at end of file diff --git a/test/cnn_utils.c b/test/cnn_utils.c index d08635a..dce732d 100644 --- a/test/cnn_utils.c +++ b/test/cnn_utils.c @@ -4,22 +4,23 @@ #include "../src/include/colors.h" #include "../src/cnn/include/creation.h" #include "../src/cnn/include/utils.h" +#include "../src/include/colors.h" int main() { printf("Création du réseau\n"); Network* network = create_network_lenet5(0, 0, 3, 2, 32, 1); - printf("OK\n"); + printf(GREEN "OK\n" RESET); printf("Copie du réseau\n"); Network* network_cp = copy_network(network); - printf("OK\n"); + printf(GREEN "OK\n" RESET); printf("Vérification de l'égalité des réseaux\n"); if (! equals_networks(network, network_cp)) { - printf_error("Les deux réseaux obtenus ne sont pas égaux.\n"); + printf_error(RED "Les deux réseaux obtenus ne sont pas égaux.\n" RESET); exit(1); } - printf("OK\n"); + printf(GREEN "OK\n" RESET); return 0; } \ No newline at end of file diff --git a/test/mnist_data_io.c b/test/mnist_data_io.c index d413b63..b74ccb1 100644 --- a/test/mnist_data_io.c +++ b/test/mnist_data_io.c @@ -3,6 +3,7 @@ #include #include "../src/mnist/include/mnist.h" +#include "../src/include/colors.h" void read_test(int nb_images, int width, int height, int*** images, unsigned int* labels) { @@ -10,7 +11,7 @@ void read_test(int nb_images, int width, int height, int*** images, unsigned int for (int i=0; i < nb_images; i++) { (void)labels[i]; } - printf("\tOK\n"); + printf(GREEN "\tOK\n" RESET); printf("\tLecture des images\n"); for (int i=0; i < nb_images; i++) { for (int j=0; j < height; j++) { @@ -19,12 +20,12 @@ void read_test(int nb_images, int width, int height, int*** images, unsigned int } } } - printf("\tOK\n"); + printf(GREEN "\tOK\n" RESET); } int main() { - char* image_file = "data/mnist/t10k-images-idx3-ubyte"; - char* labels_file = "data/mnist/t10k-labels-idx1-ubyte"; + char* image_file = (char*)"data/mnist/t10k-images-idx3-ubyte"; + char* labels_file = (char*)"data/mnist/t10k-labels-idx1-ubyte"; printf("Chargement des paramètres\n"); int* parameters = read_mnist_images_parameters(image_file); @@ -32,21 +33,21 @@ int main() { int height = parameters[1]; int width = parameters[2]; - printf("OK\n"); + printf(GREEN "OK\n" RESET); printf("Chargement des images\n"); int*** images = read_mnist_images(image_file); - printf("OK\n"); + printf(GREEN "OK\n" RESET); printf("Chargement des labels\n"); unsigned int* labels = read_mnist_labels(labels_file); - printf("OK\n"); + printf(GREEN "OK\n" RESET); printf("Vérification de l'accès en lecture\n"); read_test(nb_images, width, height, images, labels); - printf("OK\n"); + printf(GREEN "OK\n" RESET); return 0; } \ No newline at end of file diff --git a/test/mnist_neural_network.c b/test/mnist_neural_network.c index 334e902..61ed195 100644 --- a/test/mnist_neural_network.c +++ b/test/mnist_neural_network.c @@ -5,17 +5,18 @@ #include "../src/mnist/include/neural_network.h" #include "../src/mnist/include/neuron_io.h" +#include "../src/include/colors.h" int main() { printf("Création du réseau\n"); Network* network = (Network*)malloc(sizeof(Network)); int tab[5] = {30, 25, 20, 15, 10}; network_creation(network, tab, 5); - printf("OK\n"); + printf(GREEN "OK\n" RESET); printf("Initialisation du réseau\n"); network_initialisation(network); - printf("OK\n"); + printf(GREEN "OK\n" RESET); deletion_of_network(network); return 0; diff --git a/test/mnist_neuron_io.c b/test/mnist_neuron_io.c index b36702d..fee7dfe 100644 --- a/test/mnist_neuron_io.c +++ b/test/mnist_neuron_io.c @@ -6,6 +6,7 @@ #include "../src/mnist/include/neuron_io.h" #include "../src/mnist/include/neural_network.h" +#include "../src/include/colors.h" Neuron* creer_neuron(int nb_sortants) { @@ -63,20 +64,20 @@ Network* create_network(int nb_layers, int nb_max_neurons, int nb_min_neurons) { int main() { printf("Création du réseau\n"); Network* network = create_network(5, 300, 10); - printf("OK\n"); + printf(GREEN "OK\n" RESET); printf("Écriture du réseau\n"); - write_network(".test-cache/neuron_io.bin", network); - printf("OK\n"); + write_network((char*)".test-cache/neuron_io.bin", network); + printf(GREEN "OK\n" RESET); printf("Vérification de l'accès en lecture\n"); - Network* network2 = read_network(".test-cache/neuron_io.bin"); - printf("OK\n"); + Network* network2 = read_network((char*)".test-cache/neuron_io.bin"); + printf(GREEN "OK\n" RESET); printf("Suppression des réseaux\n"); deletion_of_network(network); deletion_of_network(network2); - printf("OK\n"); + printf(GREEN "OK\n" RESET); return 0; } \ No newline at end of file diff --git a/test/mnist_utils.sh b/test/mnist_utils.sh index 5a801b2..c3d4b60 100755 --- a/test/mnist_utils.sh +++ b/test/mnist_utils.sh @@ -7,17 +7,17 @@ make $OUT/mnist-utils echo "Compte des labels" "$OUT/mnist-utils" count-labels -l data/mnist/t10k-labels-idx1-ubyte -echo "OK" +echo -e "\033[32mOK\033[0m" echo "Création du réseau" mkdir -p .test-cache "$OUT/mnist-utils" creer-reseau -n 3 -o .test-cache/reseau.bin -echo "OK" +echo -e "\033[32mOK\033[0m" echo "Affichage poids" "$OUT/mnist-utils" print-poids -r .test-cache/reseau.bin > /dev/null -echo "OK" +echo -e "\033[32mOK\033[0m" echo "Affichage biais" "$OUT/mnist-utils" print-biais -r .test-cache/reseau.bin > /dev/null -echo "OK" +echo -e "\033[32mOK\033[0m"