This commit is contained in:
julienChemillier 2022-11-03 11:03:31 +01:00
commit 03944c4e0f
4 changed files with 5 additions and 209 deletions

View File

@ -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)/colors.o $(BUILDDIR)/mnist.o
$(CC) $(CFLAGS) $^ -o $@
$(BUILDDIR)/cnn-main-cuda: $(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_cuda_convolution.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)/colors.o $(BUILDDIR)/mnist.o
$(NVCC) $(NVCCFLAGS) $^ -o $@
$(BUILDDIR)/cnn_%.o: $(CNN_SRCDIR)/%.c $(CNN_SRCDIR)/include/%.h
@ -107,7 +107,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) $(CFLAGS) $^ -o $@
$(BUILDDIR)/test-cnn_%: test/cnn_%.cu $(BUILDDIR)/cnn_cuda_%.o $(BUILDDIR)/colors.o $(BUILDDIR)/mnist.o $(CNN_OBJ)
$(BUILDDIR)/test-cnn_%: test/cnn_%.cu $(BUILDDIR)/cnn_cuda_%.o $(BUILDDIR)/colors.o $(BUILDDIR)/mnist.o
ifndef NVCC_INSTALLED
@echo "nvcc not found, skipping"
else

206
make.sh
View File

@ -1,206 +0,0 @@
#!/bin/bash
# C compiler can be defined with the $CC environment variable
OUT="out"
set -e
compile_cuda () {
# nvcc will compile .c files as if they did not have
# CUDA program parts so we need to copy them to .cu
mv $1 "$1"u
echo "" > "$1" # If we compile file.cu, file.c needs to exist to, even if it is empty
nvcc "$1"u ${*:1}
mv "$1"u "$1"
}
build () {
mkdir -p "$OUT"
[[ $1 ]] || set "mnist-main"
case $1 in
"mnist-main")
echo "Compilation de src/mnist/main.c";
$CC src/mnist/main.c -o "$OUT/mnist_main" $FLAGS;
echo "Fait.";
return 0;;
"mnist-preview")
echo "Compilation de src/mnist/preview.c";
$CC src/mnist/preview.c -o "$OUT/mnist_preview" $FLAGS;
echo "Fait.";
return 0;;
"mnist-utils")
echo "Compilation de src/mnist/utils.c";
$CC "src/mnist/utils.c" -o "$OUT/mnist_utils" $FLAGS;
echo "Fait.";
return 0;;
"mnist")
build mnist-main;
build mnist-preview;
build mnist-utils;;
"cnn-main")
echo "Compilation de src/cnn/main.c";
$CC "src/cnn/main.c" -o "$OUT/cnn_main" $FLAGS;
echo "Fait.";;
"cnn")
build cnn-main;;
"test")
rm "$OUT/test_"* || true;
for i in "test/"*".c"; do
echo "Compilation de $i";
$CC "$i" -o "$OUT/test_$(echo $i | awk -F. '{print $1}' | awk -F/ '{print $NF}')" $FLAGS;
echo "Fait.";
done;
if ! command -v nvcc &> /dev/null; then
echo "Tests CUDA évités";
elif [[ $SKIP_CUDA == 1 ]]; then
echo "Tests CUDA évités";
else
for i in "test/"*".cu"; do
echo "Compilation de $i";
nvcc "$i" -o "$OUT/test_$(echo $i | awk -F. '{print $1}' | awk -F/ '{print $NF}')";
echo "Fait.";
done;
fi;
return 0;;
*)
echo -e "\033[1m\033[34m### Building mnist ###\033[0m";
build mnist-main;
build mnist-preview;
build mnist-utils;
echo -e "\033[1m\033[34m### Building cnn ###\033[0m";
build cnn;
echo -e "\033[1m\033[34m### Building tests ###\033[0m";
build test;
return 0;;
esac
}
preview () {
case $1 in
"train")
[[ -f "$OUT/mnist_preview" ]] || $0 build mnist-preview;
"$OUT/mnist_preview" data/mnist/train-images-idx3-ubyte data/mnist/train-labels-idx1-ubyte;
return 0;;
"t10k")
[[ -f "$OUT/mnist_preview" ]] || $0 build mnist-preview;
"$OUT/mnist_preview" data/mnist/t10k-images-idx3-ubyte data/mnist/t10k-labels-idx1-ubyte;
return 0;;
*)
build mnist-preview;
return 0;;
esac
}
test () {
case $1 in
"run")
build test;
mkdir -p .test-cache;
for i in "$OUT/test_"*; do
echo "--- $i ---";
$i;
done
for i in "test/"*".sh"; do
echo "--- $i ---";
chmod +x "$i";
"$i" "$OUT" "$0";
done;
return 0;;
*)
build test;
return 0;;
esac
}
train () {
[[ -f "$OUT/mnist_main" ]] || build mnist-main
[[ $1 ]] || set -- "train"
[[ $2 == "-r" || $2 == "--recover" ]] && RECOVER="-r .cache/reseau.bin"
mkdir -p .cache
"$OUT/mnist_main" train \
--images "data/mnist/$1-images-idx3-ubyte" \
--labels "data/mnist/$1-labels-idx1-ubyte" \
--out ".cache/reseau.bin" \
$RECOVER
return 0
}
test_reseau () {
[[ -f "$OUT/mnist_main" ]] || build mnist-main
[[ $1 ]] || set -- "train"
[[ -f ".cache/reseau.bin" ]] || train train
"$OUT/mnist_main" test \
--images "data/mnist/$1-images-idx3-ubyte" \
--labels "data/mnist/$1-labels-idx1-ubyte" \
--modele ".cache/reseau.bin"
return 0
}
recognize () {
if [[ $1 ]]; then
[[ $2 ]] || set -- "$2" "text"
[[ -f "$OUT/mnist_main" ]] || build mnist-main
[[ -f ".cache/reseau.bin" ]] || train train
"$OUT/mnist_main" recognize \
--modele ".cache/reseau.bin" \
--in "$1" \
--out "$2"
return 0
else
echo "Pas de fichier d'entrée spécifié. Abandon"
return 1
fi
}
utils () {
[[ -f "$OUT/mnist_utils" ]] || build mnist-utils
"$OUT/mnist_utils" ${*:1}
return 0
}
webserver () {
[[ -f "$OUT/mnist_main" ]] || build mnist-main
[[ -f ".cache/reseau.bin" ]] || train train
FLASK_APP="src/webserver/app.py" flask run
return 0
}
usage () {
echo "Usage:"
echo -e "\t$0 build ( test | all | ... )"
echo -e "\t\t\tmnist: mnist"
echo -e "\t\t\t\tmnist-main"
echo -e "\t\t\t\tmnist-preview"
echo -e "\t\t\t\tmnist-utils"
echo -e "\t\t\tcnn: cnn"
echo -e "\t\t\t\tcnn-main\n"
echo -e "\t$0 train ( train | t10k ) ( -r | --recover )"
echo -e "\t$0 preview ( train | t10k )"
echo -e "\t$0 test_reseau ( train | t10k )\n"
echo -e "\t$0 recognize [FILENAME] ( text | json )"
echo -e "\t$0 utils ( help )\n"
echo -e "\t$0 test ( run )"
echo -e "\t$0 webserver\n"
echo -e "Les fichiers de test sont recompilés à chaque exécution,\nles autres programmes sont compilés automatiquement si manquants\n"
echo -e "La plupart des options listées ici sont juste faites pour une utilisation plus rapide des commandes fréquentes,"
echo -e "d'autres options sont uniquement disponibles via les fichiers binaires dans '$OUT'"
}
[[ $CC ]] || CC=gcc
if [[ "$CC" == "gcc" ]]; then
FLAGS="-std=c99 -lm -lpthread -Wall -Wextra" # GCC flags
elif [[ "$CC" == "nvcc" ]]; then
CC=compile_cuda
FLAGS="" # NVCC flags
else
FLAGS=""
fi
if [[ $1 && $(type "$1") = *"is a"*"function"* || $(type "$1") == *"est une fonction"* ]]; then
$1 ${*:2} # Call the function
else
usage
exit 1
fi;

View File

@ -147,6 +147,7 @@ void make_convolution_device(Kernel_cnn* kernel, float*** input, float*** output
}
#endif
extern "C" {
void make_convolution(Kernel_cnn* kernel, float*** input, float*** output, int output_dim) {
#ifndef __CUDACC__
@ -155,3 +156,5 @@ void make_convolution(Kernel_cnn* kernel, float*** input, float*** output, int o
make_convolution_device(kernel, input, output, output_dim);
#endif
}
}

View File

@ -5,7 +5,6 @@
#include <math.h>
#include <time.h>
#include "../src/cnn/include/make.h"
#include "../src/cnn/include/convolution.h"
#include "../src/cnn/include/struct.h"