From fd36226600102568507b8efa0104f0dfcc15006d Mon Sep 17 00:00:00 2001 From: augustin64 Date: Fri, 12 May 2023 16:16:34 +0200 Subject: [PATCH] Move generic files to `src/common` --- Makefile | 13 ++++---- src/cnn/backpropagation.c | 2 +- src/cnn/backpropagation.cu | 2 +- src/cnn/cnn.c | 6 ++-- src/cnn/convolution.c | 2 +- src/cnn/convolution.cu | 2 +- src/cnn/creation.c | 32 +++++++++++++++++--- src/cnn/export.c | 5 +-- src/cnn/free.c | 2 +- src/cnn/function.c | 4 +-- src/cnn/function.cu | 4 +-- src/cnn/initialisation.c | 2 +- src/cnn/jpeg.c | 5 +-- src/cnn/main.c | 3 +- src/cnn/make.c | 4 +-- src/cnn/make.cu | 4 +-- src/cnn/matrix_multiplication.cu | 4 +-- src/cnn/neuron_io.c | 4 +-- src/cnn/preview.c | 2 +- src/cnn/test_network.c | 4 +-- src/cnn/train.c | 8 ++--- src/cnn/utils.c | 4 +-- src/{ => common}/colors.c | 0 src/{ => common}/include/colors.h | 0 src/{ => common}/include/memory_management.h | 0 src/{ => common}/include/mnist.h | 0 src/{ => common}/include/utils.h | 0 src/{ => common}/memory_management.c | 0 src/{ => common}/memory_management.cu | 0 src/{ => common}/mnist.c | 0 src/{ => common}/utils.c | 0 src/{ => common}/utils.cu | 0 src/dense/main.c | 9 +++--- src/dense/preview.c | 2 +- src/dense/utils.c | 2 +- test/cnn_convolution.cu | 6 ++-- test/cnn_function.cu | 6 ++-- test/cnn_matrix_multiplication.cu | 6 ++-- test/cnn_neuron_io.c | 3 +- test/cnn_structure.c | 3 +- test/cnn_utils.c | 3 +- test/dense_data_io.c | 4 +-- test/dense_neural_network.c | 2 +- test/dense_neuron_io.c | 4 +-- test/memory_management.c | 4 +-- test/memory_management.cu | 6 ++-- 46 files changed, 102 insertions(+), 76 deletions(-) rename src/{ => common}/colors.c (100%) rename src/{ => common}/include/colors.h (100%) rename src/{ => common}/include/memory_management.h (100%) rename src/{ => common}/include/mnist.h (100%) rename src/{ => common}/include/utils.h (100%) rename src/{ => common}/memory_management.c (100%) rename src/{ => common}/memory_management.cu (100%) rename src/{ => common}/mnist.c (100%) rename src/{ => common}/utils.c (100%) rename src/{ => common}/utils.cu (100%) diff --git a/Makefile b/Makefile index 5571894..5ceb88d 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,9 @@ CUDA_INCLUDE := /opt/cuda/include # Default installation path for ArchLinux, may NVCC_INSTALLED := $(shell command -v $(NVCC) 2> /dev/null) -DENSE_SRCDIR := $(SRCDIR)/dense -CNN_SRCDIR := $(SRCDIR)/cnn +COMMON_SRCDIR := $(SRCDIR)/common +DENSE_SRCDIR := $(SRCDIR)/dense +CNN_SRCDIR := $(SRCDIR)/cnn DENSE_SRC := $(wildcard $(DENSE_SRCDIR)/*.c) CNN_SRC := $(wildcard $(CNN_SRCDIR)/*.c) @@ -146,14 +147,14 @@ endif # # Build general files # -$(BUILDDIR)/%.o: $(SRCDIR)/%.c $(SRCDIR)/include/%.h +$(BUILDDIR)/%.o: $(COMMON_SRCDIR)/%.c $(COMMON_SRCDIR)/include/%.h $(CC) -c $< -o $@ $(CFLAGS) -$(BUILDDIR)/%.cuda.o: $(SRCDIR)/%.c $(SRCDIR)/include/%.h +$(BUILDDIR)/%.cuda.o: $(COMMON_SRCDIR)/%.c $(COMMON_SRCDIR)/include/%.h $(CC) -c $< -o $@ $(CFLAGS) -DUSE_CUDA -lcuda -I$(CUDA_INCLUDE) ifdef NVCC_INSTALLED -$(BUILDDIR)/cuda_%.o: $(SRCDIR)/%.cu $(SRCDIR)/include/%.h +$(BUILDDIR)/cuda_%.o: $(COMMON_SRCDIR)/%.cu $(COMMON_SRCDIR)/include/%.h $(NVCC) $(NVCCFLAGS) -c -dc $< -o $@ else @echo "$(NVCC) not found, skipping" @@ -182,7 +183,7 @@ $(BUILDDIR)/test-dense_%: $(TEST_SRCDIR)/dense_%.c $(DENSE_OBJ) $(BUILDDIR)/colo $(BUILDDIR)/test-memory_management: $(TEST_SRCDIR)/memory_management.c $(BUILDDIR)/colors.o $(BUILDDIR)/utils.o $(BUILDDIR)/test_memory_management.o $(CC) $^ -o $@ $(CFLAGS) $(LD_CFLAGS) -$(BUILDDIR)/test_memory_management.o: $(SRCDIR)/memory_management.c $(SRCDIR)/include/memory_management.h +$(BUILDDIR)/test_memory_management.o: $(COMMON_SRCDIR)/memory_management.c $(COMMON_SRCDIR)/include/memory_management.h $(CC) -c $< -o $@ $(CFLAGS) -DTEST_MEMORY_MANAGEMENT ifdef NVCC_INSTALLED diff --git a/src/cnn/backpropagation.c b/src/cnn/backpropagation.c index fa8499f..e444540 100644 --- a/src/cnn/backpropagation.c +++ b/src/cnn/backpropagation.c @@ -3,7 +3,7 @@ #include #include "include/backpropagation.h" -#include "../include/utils.h" +#include "../common/include/utils.h" #include "include/struct.h" #include "include/config.h" diff --git a/src/cnn/backpropagation.cu b/src/cnn/backpropagation.cu index fa8499f..e444540 100644 --- a/src/cnn/backpropagation.cu +++ b/src/cnn/backpropagation.cu @@ -3,7 +3,7 @@ #include #include "include/backpropagation.h" -#include "../include/utils.h" +#include "../common/include/utils.h" #include "include/struct.h" #include "include/config.h" diff --git a/src/cnn/cnn.c b/src/cnn/cnn.c index 4b7385e..7689ac5 100644 --- a/src/cnn/cnn.c +++ b/src/cnn/cnn.c @@ -4,7 +4,9 @@ #include // Is it used ? #include -#include "../include/memory_management.h" +#include "../common/include/memory_management.h" +#include "../common/include/colors.h" +#include "../common/include/utils.h" #include "include/backpropagation.h" #include "include/initialisation.h" #include "include/function.h" @@ -12,8 +14,6 @@ #include "include/update.h" #include "include/make.h" -#include "../include/colors.h" -#include "../include/utils.h" #include "include/cnn.h" // Augmente les dimensions de l'image d'entrée diff --git a/src/cnn/convolution.c b/src/cnn/convolution.c index 4219703..d0a44be 100644 --- a/src/cnn/convolution.c +++ b/src/cnn/convolution.c @@ -3,7 +3,7 @@ #include #include "include/struct.h" -#include "../include/utils.h" +#include "../common/include/utils.h" #include "include/config.h" diff --git a/src/cnn/convolution.cu b/src/cnn/convolution.cu index 4219703..d0a44be 100644 --- a/src/cnn/convolution.cu +++ b/src/cnn/convolution.cu @@ -3,7 +3,7 @@ #include #include "include/struct.h" -#include "../include/utils.h" +#include "../common/include/utils.h" #include "include/config.h" diff --git a/src/cnn/creation.c b/src/cnn/creation.c index 3c488f4..bca7a90 100644 --- a/src/cnn/creation.c +++ b/src/cnn/creation.c @@ -1,11 +1,11 @@ #include #include -#include "../include/memory_management.h" +#include "../common/include/memory_management.h" +#include "../common/include/colors.h" +#include "../common/include/utils.h" #include "include/initialisation.h" -#include "../include/colors.h" #include "include/function.h" -#include "../include/utils.h" #include "include/creation.h" @@ -38,7 +38,7 @@ Network* create_network(int max_size, float learning_rate, int dropout, int acti return network; } -Network* create_network_lenet5(float learning_rate, int dropout, int activation, int initialisation, int input_dim, int input_depth) { +/*Network* create_network_lenet5(float learning_rate, int dropout, int activation, int initialisation, int input_dim, int input_depth) { Network* network = create_network(8, learning_rate, dropout, activation, initialisation, input_dim, input_depth); add_convolution(network, 6, 28, activation); add_average_pooling(network, 14); @@ -48,8 +48,32 @@ Network* create_network_lenet5(float learning_rate, int dropout, int activation, add_dense(network, 84, activation); add_dense(network, 10, SOFTMAX); return network; +}*/ +Network* create_network_lenet5(float learning_rate, int dropout, int activation, int initialisation, int input_dim, int input_depth) { + input_dim = 260; + input_depth = 3; + Network* network = create_network(16, learning_rate, dropout, activation, initialisation, input_dim, input_depth); + printf_warning("Creating large network"); + printf(" %d %d\n", input_dim, input_depth); + add_convolution(network, 6, 258, activation); + add_convolution(network, 16, 256, activation); + add_average_pooling(network, 64); + add_convolution(network, 16, 60, activation); + add_average_pooling(network, 30); + add_convolution(network, 16, 26, activation); + add_convolution(network, 16, 22, activation); + add_convolution(network, 16, 18, activation); + add_dense_linearisation(network, 840, activation); + add_dense(network, 520, activation); + add_dense(network, 420, activation); + add_dense(network, 320, activation); + add_dense(network, 220, activation); + add_dense(network, 120, activation); + add_dense(network, 50, SOFTMAX); + return network; } + Network* create_simple_one(float learning_rate, int dropout, int activation, int initialisation, int input_dim, int input_depth) { Network* network = create_network(3, learning_rate, dropout, activation, initialisation, input_dim, input_depth); add_dense_linearisation(network, 80, activation); diff --git a/src/cnn/export.c b/src/cnn/export.c index abedf1e..d22256b 100644 --- a/src/cnn/export.c +++ b/src/cnn/export.c @@ -4,10 +4,11 @@ #include #include + +#include "../common/include/colors.h" #include "include/backpropagation.h" +#include "../common/include/mnist.h" #include "include/neuron_io.h" -#include "../include/colors.h" -#include "../include/mnist.h" #include "include/struct.h" #include "include/jpeg.h" #include "include/free.h" diff --git a/src/cnn/free.c b/src/cnn/free.c index 539b78e..fe361a5 100644 --- a/src/cnn/free.c +++ b/src/cnn/free.c @@ -1,7 +1,7 @@ #include #include -#include "../include/memory_management.h" +#include "../common/include/memory_management.h" #include "include/free.h" diff --git a/src/cnn/function.c b/src/cnn/function.c index d004020..b7749d8 100644 --- a/src/cnn/function.c +++ b/src/cnn/function.c @@ -2,8 +2,8 @@ #include #include -#include "../include/colors.h" -#include "../include/utils.h" +#include "../common/include/colors.h" +#include "../common/include/utils.h" #include "include/config.h" diff --git a/src/cnn/function.cu b/src/cnn/function.cu index d004020..b7749d8 100644 --- a/src/cnn/function.cu +++ b/src/cnn/function.cu @@ -2,8 +2,8 @@ #include #include -#include "../include/colors.h" -#include "../include/utils.h" +#include "../common/include/colors.h" +#include "../common/include/utils.h" #include "include/config.h" diff --git a/src/cnn/initialisation.c b/src/cnn/initialisation.c index e30c237..e7efa4d 100644 --- a/src/cnn/initialisation.c +++ b/src/cnn/initialisation.c @@ -1,7 +1,7 @@ #include #include -#include "../include/colors.h" +#include "../common/include/colors.h" #include "include/initialisation.h" // glorot (wavier initialisation) linear, tanh, softmax, logistic (1/(fan_in+fan_out/2)) diff --git a/src/cnn/jpeg.c b/src/cnn/jpeg.c index 723c39f..9e21a76 100644 --- a/src/cnn/jpeg.c +++ b/src/cnn/jpeg.c @@ -5,9 +5,10 @@ #include #include +#include "../common/include/utils.h" +#include "../common/include/colors.h" + #include "include/jpeg.h" -#include "../include/utils.h" -#include "../include/colors.h" // How to load a JPEG using libjpeg: https://www.tspi.at/2020/03/20/libjpegexample.html imgRawImage* loadJpegImageFile(char* lpFilename) { diff --git a/src/cnn/main.c b/src/cnn/main.c index a641b68..7375b1d 100644 --- a/src/cnn/main.c +++ b/src/cnn/main.c @@ -5,9 +5,10 @@ #include #include + +#include "../common/include/colors.h" #include "include/initialisation.h" #include "include/test_network.h" -#include "../include/colors.h" #include "include/function.h" #include "include/creation.h" #include "include/train.h" diff --git a/src/cnn/make.c b/src/cnn/make.c index 6c21611..5aca3ad 100644 --- a/src/cnn/make.c +++ b/src/cnn/make.c @@ -2,9 +2,9 @@ #include #include +#include "../common/include/colors.h" +#include "../common/include/utils.h" #include "include/convolution.h" -#include "../include/colors.h" -#include "../include/utils.h" #include "include/make.h" diff --git a/src/cnn/make.cu b/src/cnn/make.cu index 6c21611..5aca3ad 100644 --- a/src/cnn/make.cu +++ b/src/cnn/make.cu @@ -2,9 +2,9 @@ #include #include +#include "../common/include/colors.h" +#include "../common/include/utils.h" #include "include/convolution.h" -#include "../include/colors.h" -#include "../include/utils.h" #include "include/make.h" diff --git a/src/cnn/matrix_multiplication.cu b/src/cnn/matrix_multiplication.cu index fba1104..b870fee 100644 --- a/src/cnn/matrix_multiplication.cu +++ b/src/cnn/matrix_multiplication.cu @@ -2,8 +2,8 @@ #include #include -#include "../include/colors.h" -#include "../include/utils.h" +#include "../common/include/colors.h" +#include "../common/include/utils.h" #define BLOCKSIZE_x 16 #define BLOCKSIZE_y 16 diff --git a/src/cnn/neuron_io.c b/src/cnn/neuron_io.c index a009f59..44b7309 100644 --- a/src/cnn/neuron_io.c +++ b/src/cnn/neuron_io.c @@ -3,8 +3,8 @@ #include #include -#include "../include/memory_management.h" -#include "../include/colors.h" +#include "../common/include/memory_management.h" +#include "../common/include/colors.h" #include "include/function.h" #include "include/struct.h" diff --git a/src/cnn/preview.c b/src/cnn/preview.c index a4a120e..447f98f 100644 --- a/src/cnn/preview.c +++ b/src/cnn/preview.c @@ -3,7 +3,7 @@ #include #include -#include "../include/utils.h" +#include "../common/include/utils.h" #include "include/jpeg.h" diff --git a/src/cnn/test_network.c b/src/cnn/test_network.c index 6c33117..92351ae 100644 --- a/src/cnn/test_network.c +++ b/src/cnn/test_network.c @@ -3,8 +3,8 @@ #include #include -#include "../include/memory_management.h" -#include "../include/mnist.h" +#include "../common/include/memory_management.h" +#include "../common/include/mnist.h" #include "include/neuron_io.h" #include "include/struct.h" #include "include/jpeg.h" diff --git a/src/cnn/train.c b/src/cnn/train.c index 62515db..3a8c068 100644 --- a/src/cnn/train.c +++ b/src/cnn/train.c @@ -7,13 +7,13 @@ #include #include -#include "../include/memory_management.h" -#include "../include/mnist.h" +#include "../common/include/memory_management.h" +#include "../common/include/mnist.h" #include "include/initialisation.h" #include "include/test_network.h" #include "include/neuron_io.h" -#include "../include/colors.h" -#include "../include/utils.h" +#include "../common/include/colors.h" +#include "../common/include/utils.h" #include "include/function.h" #include "include/creation.h" #include "include/update.h" diff --git a/src/cnn/utils.c b/src/cnn/utils.c index 8de8b51..0ee99ce 100644 --- a/src/cnn/utils.c +++ b/src/cnn/utils.c @@ -4,8 +4,8 @@ #include #include -#include "../include/memory_management.h" -#include "../include/colors.h" +#include "../common/include/memory_management.h" +#include "../common/include/colors.h" #include "include/struct.h" #define copyVar(var) network_cp->var = network->var diff --git a/src/colors.c b/src/common/colors.c similarity index 100% rename from src/colors.c rename to src/common/colors.c diff --git a/src/include/colors.h b/src/common/include/colors.h similarity index 100% rename from src/include/colors.h rename to src/common/include/colors.h diff --git a/src/include/memory_management.h b/src/common/include/memory_management.h similarity index 100% rename from src/include/memory_management.h rename to src/common/include/memory_management.h diff --git a/src/include/mnist.h b/src/common/include/mnist.h similarity index 100% rename from src/include/mnist.h rename to src/common/include/mnist.h diff --git a/src/include/utils.h b/src/common/include/utils.h similarity index 100% rename from src/include/utils.h rename to src/common/include/utils.h diff --git a/src/memory_management.c b/src/common/memory_management.c similarity index 100% rename from src/memory_management.c rename to src/common/memory_management.c diff --git a/src/memory_management.cu b/src/common/memory_management.cu similarity index 100% rename from src/memory_management.cu rename to src/common/memory_management.cu diff --git a/src/mnist.c b/src/common/mnist.c similarity index 100% rename from src/mnist.c rename to src/common/mnist.c diff --git a/src/utils.c b/src/common/utils.c similarity index 100% rename from src/utils.c rename to src/common/utils.c diff --git a/src/utils.cu b/src/common/utils.cu similarity index 100% rename from src/utils.cu rename to src/common/utils.cu diff --git a/src/dense/main.c b/src/dense/main.c index 3703f80..f7596be 100644 --- a/src/dense/main.c +++ b/src/dense/main.c @@ -6,11 +6,12 @@ #include #include -#include "include/main.h" -#include "../include/mnist.h" -#include "../include/colors.h" -#include "include/neuron_io.h" #include "include/neural_network.h" +#include "../common/include/colors.h" +#include "../common/include/mnist.h" +#include "include/neuron_io.h" + +#include "include/main.h" #define EPOCHS 10 #define BATCHES 100 diff --git a/src/dense/preview.c b/src/dense/preview.c index e0d4965..47651f6 100644 --- a/src/dense/preview.c +++ b/src/dense/preview.c @@ -3,7 +3,7 @@ #include #include -#include "../include/mnist.h" +#include "../common/include/mnist.h" void print_image(unsigned int width, unsigned int height, int** image) { diff --git a/src/dense/utils.c b/src/dense/utils.c index 38424fb..15db61f 100644 --- a/src/dense/utils.c +++ b/src/dense/utils.c @@ -3,9 +3,9 @@ #include #include +#include "../common/include/mnist.h" #include "include/neural_network.h" #include "include/neuron_io.h" -#include "../include/mnist.h" /* Contient un ensemble de fonctions utiles pour le débogage diff --git a/test/cnn_convolution.cu b/test/cnn_convolution.cu index c44ef7d..7738d34 100644 --- a/test/cnn_convolution.cu +++ b/test/cnn_convolution.cu @@ -6,11 +6,11 @@ #include #include -#include "../src/include/memory_management.h" +#include "../src/common/include/memory_management.h" #include "../src/cnn/include/convolution.h" +#include "../src/common/include/colors.h" +#include "../src/common/include/utils.h" #include "../src/cnn/include/struct.h" -#include "../src/include/colors.h" -#include "../src/include/utils.h" float random_float(float low, float high) { diff --git a/test/cnn_function.cu b/test/cnn_function.cu index bc5649b..09a69bd 100644 --- a/test/cnn_function.cu +++ b/test/cnn_function.cu @@ -2,10 +2,10 @@ #include #include -#include "../src/include/memory_management.h" +#include "../src/common/include/memory_management.h" +#include "../src/common/include/colors.h" +#include "../src/common/include/utils.h" #include "../src/cnn/include/function.h" -#include "../src/include/colors.h" -#include "../src/include/utils.h" #include "../src/cnn/include/config.h" diff --git a/test/cnn_matrix_multiplication.cu b/test/cnn_matrix_multiplication.cu index e3758d9..6930e84 100644 --- a/test/cnn_matrix_multiplication.cu +++ b/test/cnn_matrix_multiplication.cu @@ -6,9 +6,9 @@ #include #include "../src/cnn/include/matrix_multiplication.h" -#include "../src/include/memory_management.h" -#include "../src/include/colors.h" -#include "../src/include/utils.h" +#include "../src/common/include/memory_management.h" +#include "../src/common/include/colors.h" +#include "../src/common/include/utils.h" float random_float(float low, float high) { diff --git a/test/cnn_neuron_io.c b/test/cnn_neuron_io.c index e457841..ee9a44f 100644 --- a/test/cnn_neuron_io.c +++ b/test/cnn_neuron_io.c @@ -3,12 +3,11 @@ #include #include -#include "../src/include/colors.h" +#include "../src/common/include/colors.h" #include "../src/cnn/include/neuron_io.h" #include "../src/cnn/include/creation.h" #include "../src/cnn/include/utils.h" #include "../src/cnn/include/free.h" -#include "../src/include/colors.h" int main() { diff --git a/test/cnn_structure.c b/test/cnn_structure.c index 4a8ec2b..d1770b6 100644 --- a/test/cnn_structure.c +++ b/test/cnn_structure.c @@ -3,11 +3,10 @@ #include #include -#include "../src/include/colors.h" +#include "../src/common/include/colors.h" #include "../src/cnn/include/creation.h" #include "../src/cnn/include/utils.h" #include "../src/cnn/include/free.h" -#include "../src/include/colors.h" int main() { diff --git a/test/cnn_utils.c b/test/cnn_utils.c index 2ba3fae..d522325 100644 --- a/test/cnn_utils.c +++ b/test/cnn_utils.c @@ -1,11 +1,10 @@ #include #include -#include "../src/include/colors.h" +#include "../src/common/include/colors.h" #include "../src/cnn/include/creation.h" #include "../src/cnn/include/utils.h" #include "../src/cnn/include/free.h" -#include "../src/include/colors.h" int main() { printf("Création du réseau\n"); diff --git a/test/dense_data_io.c b/test/dense_data_io.c index 0d1d6c4..cf9ea56 100644 --- a/test/dense_data_io.c +++ b/test/dense_data_io.c @@ -2,8 +2,8 @@ #include #include -#include "../src/include/mnist.h" -#include "../src/include/colors.h" +#include "../src/common/include/colors.h" +#include "../src/common/include/mnist.h" void read_test(int nb_images, int width, int height, int*** images, unsigned int* labels) { diff --git a/test/dense_neural_network.c b/test/dense_neural_network.c index a0b07a0..9eccdab 100644 --- a/test/dense_neural_network.c +++ b/test/dense_neural_network.c @@ -5,7 +5,7 @@ #include "../src/dense/include/neural_network.h" #include "../src/dense/include/neuron_io.h" -#include "../src/include/colors.h" +#include "../src/common/include/colors.h" int main() { printf("Création du réseau\n"); diff --git a/test/dense_neuron_io.c b/test/dense_neuron_io.c index 9651a5e..c43fc0a 100644 --- a/test/dense_neuron_io.c +++ b/test/dense_neuron_io.c @@ -4,9 +4,9 @@ #include #include -#include "../src/dense/include/neuron_io.h" #include "../src/dense/include/neural_network.h" -#include "../src/include/colors.h" +#include "../src/dense/include/neuron_io.h" +#include "../src/common/include/colors.h" Neuron* creer_neuron(int nb_sortants) { diff --git a/test/memory_management.c b/test/memory_management.c index 4c008a9..7524393 100644 --- a/test/memory_management.c +++ b/test/memory_management.c @@ -2,8 +2,8 @@ #include #include -#include "../src/include/memory_management.h" -#include "../src/include/colors.h" +#include "../src/common/include/memory_management.h" +#include "../src/common/include/colors.h" #define N 350 diff --git a/test/memory_management.cu b/test/memory_management.cu index 62de138..29ea299 100644 --- a/test/memory_management.cu +++ b/test/memory_management.cu @@ -2,9 +2,9 @@ #include #include -#include "../src/include/memory_management.h" -#include "../src/include/colors.h" -#include "../src/include/utils.h" +#include "../src/common/include/memory_management.h" +#include "../src/common/include/colors.h" +#include "../src/common/include/utils.h" #define N 350