2022-10-24 12:54:51 +02:00
|
|
|
BUILDDIR := ./build
|
|
|
|
SRCDIR := ./src
|
|
|
|
CACHE_DIR := ./cache
|
|
|
|
NVCC := nvcc
|
|
|
|
|
2022-10-24 14:08:18 +02:00
|
|
|
NVCC_INSTALLED := $(shell command -v nvcc 2> /dev/null)
|
2022-10-24 12:54:51 +02:00
|
|
|
|
|
|
|
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
|
2022-10-28 12:32:25 +02:00
|
|
|
NVCCFLAGS =
|
2022-10-24 12:54:51 +02:00
|
|
|
|
|
|
|
# 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
|
2022-11-04 12:43:47 +01:00
|
|
|
$(CC) $(MNIST_SRCDIR)/main.c $(BUILDDIR)/mnist.o $(BUILDDIR)/mnist_neuron_io.o $(BUILDDIR)/mnist_neural_network.o -o $(BUILDDIR)/mnist-main $(CFLAGS)
|
2022-10-24 12:54:51 +02:00
|
|
|
|
|
|
|
$(BUILDDIR)/mnist-utils: $(MNIST_SRCDIR)/utils.c $(BUILDDIR)/mnist_neural_network.o $(BUILDDIR)/mnist_neuron_io.o $(BUILDDIR)/mnist.o
|
2022-11-04 12:43:47 +01:00
|
|
|
$(CC) $^ -o $@ $(CFLAGS)
|
2022-10-24 12:54:51 +02:00
|
|
|
|
|
|
|
$(BUILDDIR)/mnist-preview: $(MNIST_SRCDIR)/preview.c $(BUILDDIR)/mnist.o
|
2022-11-04 12:43:47 +01:00
|
|
|
$(CC) $^ -o $@ $(CFLAGS)
|
2022-10-24 12:54:51 +02:00
|
|
|
|
|
|
|
# .o files
|
|
|
|
$(BUILDDIR)/mnist.o: $(MNIST_SRCDIR)/mnist.c $(MNIST_SRCDIR)/include/mnist.h
|
2022-11-04 12:43:47 +01:00
|
|
|
$(CC) -c $< -o $@ $(CFLAGS)
|
2022-10-24 12:54:51 +02:00
|
|
|
|
|
|
|
$(BUILDDIR)/mnist_%.o: $(MNIST_SRCDIR)/%.c $(MNIST_SRCDIR)/include/%.h
|
2022-11-04 12:43:47 +01:00
|
|
|
$(CC) -c $< -o $@ $(CFLAGS)
|
2022-10-24 12:54:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Build cnn
|
|
|
|
#
|
|
|
|
cnn: $(BUILDDIR)/cnn-main;
|
|
|
|
|
2022-11-03 18:13:01 +01:00
|
|
|
$(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
|
2022-11-04 12:43:47 +01:00
|
|
|
$(CC) $^ -o $@ $(CFLAGS)
|
2022-10-24 12:54:51 +02:00
|
|
|
|
2022-11-11 11:20:30 +01:00
|
|
|
$(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
|
2022-11-01 17:24:29 +01:00
|
|
|
$(NVCC) $(NVCCFLAGS) $^ -o $@
|
|
|
|
|
2022-10-24 12:54:51 +02:00
|
|
|
$(BUILDDIR)/cnn_%.o: $(CNN_SRCDIR)/%.c $(CNN_SRCDIR)/include/%.h
|
2022-11-04 12:43:47 +01:00
|
|
|
$(CC) -c $< -o $@ $(CFLAGS)
|
2022-10-24 12:54:51 +02:00
|
|
|
|
2022-11-01 17:24:29 +01:00
|
|
|
$(BUILDDIR)/cnn_cuda_%.o: $(CNN_SRCDIR)/%.cu $(CNN_SRCDIR)/include/%.h
|
2022-10-24 14:09:10 +02:00
|
|
|
ifndef NVCC_INSTALLED
|
|
|
|
@echo "nvcc not found, skipping"
|
|
|
|
else
|
|
|
|
$(NVCC) $(NVCCFLAGS) -c $< -o $@
|
|
|
|
endif
|
2022-10-24 12:54:51 +02:00
|
|
|
#
|
|
|
|
# Build general files
|
|
|
|
#
|
|
|
|
$(BUILDDIR)/%.o: $(SRCDIR)/%.c $(SRCDIR)/include/%.h
|
2022-11-04 12:45:05 +01:00
|
|
|
$(CC) -c $< -o $@ $(CFLAGS)
|
2022-10-24 12:54:51 +02:00
|
|
|
|
2022-11-11 11:20:30 +01:00
|
|
|
$(BUILDDIR)/cuda_%.o: $(SRCDIR)/%.cu $(SRCDIR)/include/%.h
|
|
|
|
$(NVCC) $(NVCCFLAGS) -c $< -o $@
|
|
|
|
|
2022-10-24 12:54:51 +02:00
|
|
|
#
|
|
|
|
# Tests
|
|
|
|
#
|
|
|
|
run-tests: build-tests
|
|
|
|
$(foreach file, $(wildcard $(TEST_SRCDIR)/*.sh), $(file);)
|
2022-11-11 11:20:30 +01:00
|
|
|
@echo "$$(for file in build/test-*; do echo -e \\033[33m#####\\033[0m $$file \\033[33m#####\\033[0m; $$file; done)"
|
2022-10-24 12:54:51 +02:00
|
|
|
|
2022-11-01 17:24:29 +01:00
|
|
|
build-tests: prepare-tests $(TESTS_OBJ) $(BUILDDIR)/test-cnn_matrix_multiplication $(BUILDDIR)/test-cnn_convolution
|
2022-10-24 12:54:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
prepare-tests:
|
|
|
|
@rm -f $(BUILDDIR)/test-*
|
|
|
|
|
|
|
|
|
|
|
|
build/test-cnn_%: test/cnn_%.c $(CNN_OBJ) $(BUILDDIR)/colors.o $(BUILDDIR)/mnist.o
|
2022-11-04 12:43:47 +01:00
|
|
|
$(CC) $^ -o $@ $(CFLAGS)
|
2022-10-24 12:54:51 +02:00
|
|
|
|
|
|
|
# mnist.o est déjà inclus en tant que mnist_mnist.o
|
|
|
|
build/test-mnist_%: test/mnist_%.c $(MNIST_OBJ) $(BUILDDIR)/colors.o
|
2022-11-04 12:43:47 +01:00
|
|
|
$(CC) $^ -o $@ $(CFLAGS)
|
2022-10-24 12:54:51 +02:00
|
|
|
|
2022-11-11 11:20:30 +01:00
|
|
|
$(BUILDDIR)/test-cnn_%: test/cnn_%.cu $(BUILDDIR)/cnn_cuda_%.o $(BUILDDIR)/cuda_utils.o $(BUILDDIR)/colors.o $(BUILDDIR)/mnist.o
|
2022-10-24 14:09:10 +02:00
|
|
|
ifndef NVCC_INSTALLED
|
|
|
|
@echo "nvcc not found, skipping"
|
|
|
|
else
|
|
|
|
$(NVCC) $(NVCCFLAGS) $^ -o $@
|
|
|
|
endif
|
2022-10-24 12:54:51 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# 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)/*
|