mirror of
https://github.com/augustin64/projet-tipe
synced 2025-02-02 19:39:39 +01:00
Move to Makefile
This commit is contained in:
parent
35ac91585f
commit
cf050de1d6
12
.github/workflows/tests.yml
vendored
12
.github/workflows/tests.yml
vendored
@ -13,13 +13,11 @@ jobs:
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: compile all
|
||||
run: ./make.sh build all
|
||||
- name: run tests
|
||||
run: ./make.sh test run
|
||||
- name: mnist main test
|
||||
run: out/mnist_main train
|
||||
- name: run-tests
|
||||
run: make run-tests
|
||||
- name: mnist main train
|
||||
run: build/mnist-main train
|
||||
--epochs 1
|
||||
--images data/mnist/t10k-images-idx3-ubyte
|
||||
--labels data/mnist/t10k-labels-idx1-ubyte
|
||||
--out reseau.bin
|
||||
--out mnist-reseau.bin
|
||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,10 +1,10 @@
|
||||
**/out
|
||||
**/a.out
|
||||
**/__pycache__
|
||||
|
||||
.cache
|
||||
.test-cache
|
||||
.vscode
|
||||
build/*
|
||||
*.bin
|
||||
app-secret
|
||||
|
||||
data/50States10K
|
126
Makefile
Normal file
126
Makefile
Normal file
@ -0,0 +1,126 @@
|
||||
BUILDDIR := ./build
|
||||
SRCDIR := ./src
|
||||
CACHE_DIR := ./cache
|
||||
NVCC := nvcc
|
||||
CC := gcc
|
||||
|
||||
|
||||
MNIST_SRCDIR := $(SRCDIR)/mnist
|
||||
CNN_SRCDIR := $(SRCDIR)/cnn
|
||||
|
||||
MNIST_SRC := $(wildcard $(MNIST_SRCDIR)/*.c)
|
||||
CNN_SRC := $(wildcard $(CNN_SRCDIR)/*.c)
|
||||
CNN_SRC_CUDA := $(wildcard $(CNN_SRCDIR)/*.cu)
|
||||
|
||||
MNIST_OBJ = $(filter-out $(BUILDDIR)/mnist_main.o $(BUILDDIR)/mnist_utils.o $(BUILDDIR)/mnist_preview.o, $(MNIST_SRC:$(MNIST_SRCDIR)/%.c=$(BUILDDIR)/mnist_%.o))
|
||||
CNN_OBJ = $(filter-out $(BUILDDIR)/cnn_main.o, $(CNN_SRC:$(CNN_SRCDIR)/%.c=$(BUILDDIR)/cnn_%.o))
|
||||
CNN_OBJ_CUDA = $(CNN_SRC:$(CNN_SRCDIR)/%.cu=$(BUILDDIR)/cnn_%.o)
|
||||
|
||||
|
||||
TEST_SRCDIR := test
|
||||
|
||||
TESTS_SRC = $(wildcard test/*.c)
|
||||
TESTS_SRC_CU += $(wildcard test/*.cu)
|
||||
|
||||
TESTS_OBJ = $(TESTS_SRC:test/%.c=$(BUILDDIR)/test-%) $(TESTS_SRC_CU:test/%.cu=$(BUILDDIR)/test-%)
|
||||
|
||||
# Compile flags
|
||||
CFLAGS = -std=c99 -lm -lpthread
|
||||
NVCCFLAGS =
|
||||
|
||||
# Additional warning rules
|
||||
CFLAGS += -Wall -Wextra
|
||||
NVCCFLAGS +=
|
||||
# Remove warnings about unused variables, functions, ...
|
||||
# -Wno-unused-parameter -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable
|
||||
# Compile with debug
|
||||
# -g
|
||||
|
||||
all: mnist cnn;
|
||||
#
|
||||
# Build mnist
|
||||
#
|
||||
# Executables
|
||||
mnist: $(BUILDDIR)/mnist-main $(BUILDDIR)/mnist-utils $(BUILDDIR)/mnist-preview;
|
||||
|
||||
$(BUILDDIR)/mnist-main: $(MNIST_SRCDIR)/main.c $(BUILDDIR)/mnist.o $(BUILDDIR)/mnist_neuron_io.o $(BUILDDIR)/mnist_neural_network.o
|
||||
$(CC) $(CFLAGS) $(MNIST_SRCDIR)/main.c $(BUILDDIR)/mnist.o $(BUILDDIR)/mnist_neuron_io.o $(BUILDDIR)/mnist_neural_network.o -o $(BUILDDIR)/mnist-main
|
||||
|
||||
$(BUILDDIR)/mnist-utils: $(MNIST_SRCDIR)/utils.c $(BUILDDIR)/mnist_neural_network.o $(BUILDDIR)/mnist_neuron_io.o $(BUILDDIR)/mnist.o
|
||||
$(CC) $(CFLAGS) $^ -o $@
|
||||
|
||||
$(BUILDDIR)/mnist-preview: $(MNIST_SRCDIR)/preview.c $(BUILDDIR)/mnist.o
|
||||
$(CC) $(CFLAGS) $^ -o $@
|
||||
|
||||
# .o files
|
||||
$(BUILDDIR)/mnist.o: $(MNIST_SRCDIR)/mnist.c $(MNIST_SRCDIR)/include/mnist.h
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(BUILDDIR)/mnist_%.o: $(MNIST_SRCDIR)/%.c $(MNIST_SRCDIR)/include/%.h
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
|
||||
#
|
||||
# Build cnn
|
||||
#
|
||||
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)/colors.o $(BUILDDIR)/mnist.o
|
||||
$(CC) $(CFLAGS) $^ -o $@
|
||||
|
||||
$(BUILDDIR)/cnn_%.o: $(CNN_SRCDIR)/%.c $(CNN_SRCDIR)/include/%.h
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(BUILDDIR)/cnn_%.o: $(CNN_SRCDIR)/%.cu $(CNN_SRCDIR)/include/%.h
|
||||
$(NVCC) $(NVCCFLAGS) -c $< -o $@
|
||||
#
|
||||
# Build general files
|
||||
#
|
||||
$(BUILDDIR)/%.o: $(SRCDIR)/%.c $(SRCDIR)/include/%.h
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
#
|
||||
# Tests
|
||||
#
|
||||
run-tests: build-tests
|
||||
$(foreach file, $(wildcard $(BUILDDIR)/test-*), $(file);)
|
||||
$(foreach file, $(wildcard $(TEST_SRCDIR)/*.sh), $(file);)
|
||||
|
||||
build-tests: prepare-tests $(TESTS_OBJ)
|
||||
|
||||
|
||||
prepare-tests:
|
||||
@rm -f $(BUILDDIR)/test-*
|
||||
|
||||
|
||||
build/test-cnn_%: test/cnn_%.c $(CNN_OBJ) $(BUILDDIR)/colors.o $(BUILDDIR)/mnist.o
|
||||
$(CC) $(CFLAGS) $^ -o $@
|
||||
|
||||
# mnist.o est déjà inclus en tant que mnist_mnist.o
|
||||
build/test-mnist_%: test/mnist_%.c $(MNIST_OBJ) $(BUILDDIR)/colors.o
|
||||
$(CC) $(CFLAGS) $^ -o $@
|
||||
|
||||
$(BUILDDIR)/test-cnn_matrix_multiplication: test/cnn_matrix_multiplication.cu $(BUILDDIR)/cnn_matrix_multiplication.o $(BUILDDIR)/colors.o $(BUILDDIR)/mnist.o
|
||||
$(NVCC) $(NVCCFLAGS) $^ -o $@
|
||||
|
||||
|
||||
#
|
||||
# Utils
|
||||
#
|
||||
webserver: $(CACHE_DIR)/mnist-reseau.bin
|
||||
FLASK_APP="src/webserver/app.py" flask run
|
||||
|
||||
$(CACHE_DIR)/mnist-reseau.bin: $(BUILDDIR)/mnist-main
|
||||
@mkdir -p $(CACHE_DIR)
|
||||
$(BUILDDIR)/mnist-main train \
|
||||
--images "data/mnist/train-images-idx3-ubyte" \
|
||||
--labels "data/mnist/train-labels-idx1-ubyte" \
|
||||
--out "$(CACHE_DIR)/mnist-reseau.bin"
|
||||
|
||||
|
||||
#
|
||||
# Clean project
|
||||
#
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)/*
|
||||
rm -f $(CACHE_DIR)/*
|
@ -3,12 +3,12 @@
|
||||
#include <math.h>
|
||||
#include <float.h> // Is it used ?
|
||||
|
||||
#include "../colors.h"
|
||||
#include "include/initialisation.h"
|
||||
#include "function.c"
|
||||
#include "creation.c"
|
||||
#include "make.c"
|
||||
#include "include/function.h"
|
||||
#include "include/creation.h"
|
||||
#include "include/make.h"
|
||||
|
||||
#include "../include/colors.h"
|
||||
#include "include/cnn.h"
|
||||
|
||||
// Augmente les dimensions de l'image d'entrée
|
||||
|
@ -1,8 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "include/creation.h"
|
||||
|
||||
#include "include/initialisation.h"
|
||||
#include "include/function.h"
|
||||
#include "initialisation.c"
|
||||
|
||||
#include "include/creation.h"
|
||||
|
||||
Network* create_network(int max_size, int learning_rate, int dropout, int initialisation, int input_dim, int input_depth) {
|
||||
if (dropout < 0 || dropout > 100) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "include/free.h"
|
||||
|
||||
void free_a_cube_input_layer(Network* network, int pos, int depth, int dim) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "include/function.h"
|
||||
|
||||
float max(float a, float b) {
|
||||
|
40
src/cnn/include/matrix_multiplication.h
Normal file
40
src/cnn/include/matrix_multiplication.h
Normal file
@ -0,0 +1,40 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifndef DEF_MATRIX_MULTIPLICATION_H
|
||||
#define DEF_MATRIX_MULTIPLICATION_H
|
||||
|
||||
|
||||
#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`
|
||||
*/
|
||||
__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);
|
||||
|
||||
/*
|
||||
* Multiplication de deux matrices sur le GPU
|
||||
*/
|
||||
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)
|
||||
*/
|
||||
void matrix_multiplication_host(float** m1, float** m2, float** result, int n, int p, int q);
|
||||
|
||||
/*
|
||||
* Multiplication de matrices (décide si il faut la faire sur CPU ou GPU)
|
||||
*/
|
||||
void matrix_multiplication(float** m1, float** m2, float** result, int n, int p, int q, bool use_cuda);
|
||||
#endif
|
@ -3,7 +3,6 @@
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../colors.h"
|
||||
#include "struct.h"
|
||||
|
||||
#ifndef DEF_UTILS_H
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "../colors.h"
|
||||
#include "../include/colors.h"
|
||||
#include "include/initialisation.h"
|
||||
|
||||
|
||||
|
@ -4,9 +4,12 @@
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "train.c"
|
||||
#include "include/initialisation.h"
|
||||
#include "../include/colors.h"
|
||||
#include "include/function.h"
|
||||
#include "include/creation.h"
|
||||
#include "include/train.h"
|
||||
#include "include/cnn.h"
|
||||
#include "../colors.h"
|
||||
|
||||
#include "include/main.h"
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../colors.h"
|
||||
#include "../include/colors.h"
|
||||
#include "include/make.h"
|
||||
|
||||
void make_convolution(Kernel_cnn* kernel, float*** input, float*** output, int output_dim) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "../colors.h"
|
||||
#include "../include/colors.h"
|
||||
#include "include/neuron_io.h"
|
||||
#include "include/struct.h"
|
||||
|
||||
@ -170,7 +170,7 @@ Network* read_network(char* filename) {
|
||||
}
|
||||
|
||||
network->input = (float****)malloc(sizeof(float***)*size);
|
||||
for (int i=0; i < size; i++) { // input[size][couche->depth][couche->dim][couche->dim]
|
||||
for (int i=0; i < (int)size; i++) { // input[size][couche->depth][couche->dim][couche->dim]
|
||||
network->input[i] = (float***)malloc(sizeof(float**)*network->depth[i]);
|
||||
for (int j=0; j < network->depth[i]; j++) {
|
||||
network->input[i][j] = (float**)malloc(sizeof(float*)*network->width[i]);
|
||||
|
@ -4,12 +4,15 @@
|
||||
#include <pthread.h>
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
#include "../mnist/mnist.c"
|
||||
#include "../colors.h"
|
||||
#include "neuron_io.c"
|
||||
#include "utils.c"
|
||||
#include "free.c"
|
||||
#include "cnn.c"
|
||||
#include "../mnist/include/mnist.h"
|
||||
#include "include/initialisation.h"
|
||||
#include "include/neuron_io.h"
|
||||
#include "../include/colors.h"
|
||||
#include "include/function.h"
|
||||
#include "include/creation.h"
|
||||
#include "include/utils.h"
|
||||
#include "include/free.h"
|
||||
#include "include/cnn.h"
|
||||
|
||||
#include "include/train.h"
|
||||
|
||||
@ -19,7 +22,7 @@ void* train_thread(void* parameters) {
|
||||
Network* network = param->network;
|
||||
|
||||
int*** images = param->images;
|
||||
int* labels = param->labels;
|
||||
int* labels = (int*)param->labels;
|
||||
|
||||
int width = param->width;
|
||||
int height = param->height;
|
||||
@ -32,7 +35,7 @@ void* train_thread(void* parameters) {
|
||||
if (dataset_type == 0) {
|
||||
write_image_in_network_32(images[i], height, width, network->input[0][0]);
|
||||
forward_propagation(network);
|
||||
//backward_propagation(network, labels[i]);
|
||||
backward_propagation(network, labels[i]);
|
||||
|
||||
// TODO get_indice_max(network last layer)
|
||||
// TODO if indice_max == labels[i] then accuracy += 1.
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../colors.h"
|
||||
#include "../include/colors.h"
|
||||
#include "include/struct.h"
|
||||
|
||||
#define copyVar(var) network_cp->var = network->var
|
||||
|
15
src/colors.c
Normal file
15
src/colors.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "include/colors.h"
|
||||
|
||||
void printf_error(char* string) {
|
||||
printf(BOLDRED "[ ERROR ]" RESET " %s", string);
|
||||
}
|
||||
|
||||
void printf_warning(char* string) {
|
||||
printf(BOLDYELLOW "[WARNING]" RESET " %s", string);
|
||||
}
|
||||
|
||||
void printf_info(char* string) {
|
||||
printf(BOLDBLUE "[ INFO ]" RESET " %s", string);
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef DEF_COLORS_H
|
||||
#define DEF_COLORS_H
|
||||
|
||||
@ -19,16 +21,8 @@
|
||||
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
|
||||
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
|
||||
|
||||
void printf_error(char* string) {
|
||||
printf(BOLDRED "[ ERROR ]" RESET " %s", string);
|
||||
}
|
||||
|
||||
void printf_warning(char* string) {
|
||||
printf(BOLDYELLOW "[WARNING]" RESET " %s", string);
|
||||
}
|
||||
|
||||
void printf_info(char* string) {
|
||||
printf(BOLDBLUE "[ INFO ]" RESET " %s", string);
|
||||
}
|
||||
void printf_error(char* string);
|
||||
void printf_warning(char* string);
|
||||
void printf_info(char* string);
|
||||
|
||||
#endif
|
@ -1,8 +1,6 @@
|
||||
#ifndef DEF_MAIN_H
|
||||
#define DEF_MAIN_H
|
||||
|
||||
#include "../main.c"
|
||||
|
||||
/*
|
||||
* Affiche une image ainsi que les prévisions faites par le réseau de neurones sur sa valeur
|
||||
* width, height: dimensions de l'image
|
||||
|
@ -6,7 +6,6 @@
|
||||
#ifndef DEF_MNIST_H
|
||||
#define DEF_MNIST_H
|
||||
|
||||
#include "../mnist.c"
|
||||
|
||||
uint32_t swap_endian(uint32_t val);
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
#ifndef DEF_NEURAL_NETWORK_H
|
||||
#define DEF_NEURAL_NETWORK_H
|
||||
|
||||
#include "../neural_network.c"
|
||||
|
||||
/*
|
||||
* Fonction max pour les floats
|
||||
|
@ -8,7 +8,6 @@
|
||||
#ifndef DEF_NEURON_IO_H
|
||||
#define DEF_NEURON_IO_H
|
||||
|
||||
#include "../neuron_io.c"
|
||||
|
||||
// Lecture d'un réseau neuronal
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
#ifndef DEF_PREVIEW_H
|
||||
#define DEF_PREVIEW_H
|
||||
|
||||
#include "../preview.c"
|
||||
|
||||
/*
|
||||
* Affiche un chiffre de taille width x height
|
||||
|
@ -38,9 +38,9 @@ def recognize_mnist(image):
|
||||
|
||||
try:
|
||||
output = subprocess.check_output([
|
||||
'out/mnist_main',
|
||||
'build/mnist-main',
|
||||
'recognize',
|
||||
'--modele', '.cache/reseau.bin',
|
||||
'--modele', '.cache/mnist-reseau.bin',
|
||||
'--in', '.cache/image-idx3-ubyte',
|
||||
'--out', 'json'
|
||||
]).decode("utf-8")
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../src/cnn/matrix_multiplication.cu"
|
||||
#include "../src/cnn/include/matrix_multiplication.h"
|
||||
|
||||
|
||||
float random_float(float low, float high) {
|
@ -3,11 +3,10 @@
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "../src/colors.h"
|
||||
#include "../src/cnn/neuron_io.c"
|
||||
#include "../src/cnn/creation.c"
|
||||
#include "../src/cnn/utils.c"
|
||||
|
||||
#include "../src/include/colors.h"
|
||||
#include "../src/cnn/include/neuron_io.h"
|
||||
#include "../src/cnn/include/creation.h"
|
||||
#include "../src/cnn/include/utils.h"
|
||||
|
||||
|
||||
int main() {
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../src/colors.h"
|
||||
#include "../src/cnn/creation.c"
|
||||
#include "../src/cnn/utils.c"
|
||||
#include "../src/include/colors.h"
|
||||
#include "../src/cnn/include/creation.h"
|
||||
#include "../src/cnn/include/utils.h"
|
||||
|
||||
int main() {
|
||||
printf("Création du réseau\n");
|
||||
|
@ -2,21 +2,21 @@
|
||||
|
||||
set -e
|
||||
|
||||
OUT="$1"
|
||||
[[ -f "$OUT/mnist_utils" ]] || "$2" build mnist-utils
|
||||
OUT="build"
|
||||
[[ -f "$OUT/mnist-utils" ]] || make $OUT/mnist-utils
|
||||
|
||||
echo "Compte des labels"
|
||||
"$OUT/mnist_utils" count-labels -l data/mnist/t10k-labels-idx1-ubyte > /dev/null
|
||||
"$OUT/mnist-utils" count-labels -l data/mnist/t10k-labels-idx1-ubyte > /dev/null
|
||||
echo "OK"
|
||||
|
||||
echo "Création du réseau"
|
||||
"$OUT/mnist_utils" creer-reseau -n 3 -o .test-cache/reseau.bin > /dev/null
|
||||
"$OUT/mnist-utils" creer-reseau -n 3 -o .test-cache/reseau.bin > /dev/null
|
||||
echo "OK"
|
||||
|
||||
echo "Affichage poids"
|
||||
"$OUT/mnist_utils" print-poids -r .test-cache/reseau.bin > /dev/null
|
||||
"$OUT/mnist-utils" print-poids -r .test-cache/reseau.bin > /dev/null
|
||||
echo "OK"
|
||||
|
||||
echo "Affichage biais"
|
||||
"$OUT/mnist_utils" print-biais -r .test-cache/reseau.bin > /dev/null
|
||||
"$OUT/mnist-utils" print-biais -r .test-cache/reseau.bin > /dev/null
|
||||
echo "OK"
|
Loading…
Reference in New Issue
Block a user