mirror of
https://github.com/augustin64/projet-tipe
synced 2025-02-02 19:39:39 +01:00
remove openmp dependency
time may not be accurate (now using processor time instead of real time)
This commit is contained in:
parent
5c712c0120
commit
6c7112b9b5
4
Makefile
4
Makefile
@ -27,8 +27,8 @@ TESTS_SRC_CU += $(wildcard $(TEST_SRCDIR)/*.cu)
|
|||||||
TESTS_OBJ = $(TESTS_SRC:$(TEST_SRCDIR)/%.c=$(BUILDDIR)/$(TEST_SRCDIR)-%) $(TESTS_SRC_CU:$(TEST_SRCDIR)/%.cu=$(BUILDDIR)/$(TEST_SRCDIR)-%)
|
TESTS_OBJ = $(TESTS_SRC:$(TEST_SRCDIR)/%.c=$(BUILDDIR)/$(TEST_SRCDIR)-%) $(TESTS_SRC_CU:$(TEST_SRCDIR)/%.cu=$(BUILDDIR)/$(TEST_SRCDIR)-%)
|
||||||
|
|
||||||
# Linker only flags
|
# Linker only flags
|
||||||
LD_CFLAGS = -lm -lpthread -ljpeg -fopenmp
|
LD_CFLAGS = -lm -lpthread -ljpeg
|
||||||
LD_NVCCFLAGS = -ljpeg -Xcompiler -fopenmp
|
LD_NVCCFLAGS = -ljpeg
|
||||||
|
|
||||||
# Compilation flag
|
# Compilation flag
|
||||||
CFLAGS = -Wall -Wextra -std=gnu99 -g -O3
|
CFLAGS = -Wall -Wextra -std=gnu99 -g -O3
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <omp.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "../common/include/memory_management.h"
|
#include "../common/include/memory_management.h"
|
||||||
#include "../common/include/colors.h"
|
#include "../common/include/colors.h"
|
||||||
@ -64,7 +64,7 @@ void* train_thread(void* parameters) {
|
|||||||
float loss = 0.;
|
float loss = 0.;
|
||||||
|
|
||||||
#ifdef DETAILED_TRAIN_TIMINGS
|
#ifdef DETAILED_TRAIN_TIMINGS
|
||||||
double start_time;
|
clock_t start_time;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pthread_t tid;
|
pthread_t tid;
|
||||||
@ -81,16 +81,16 @@ void* train_thread(void* parameters) {
|
|||||||
write_image_in_network_32(images[index[i]], height, width, network->input[0][0], param->offset);
|
write_image_in_network_32(images[index[i]], height, width, network->input[0][0], param->offset);
|
||||||
|
|
||||||
#ifdef DETAILED_TRAIN_TIMINGS
|
#ifdef DETAILED_TRAIN_TIMINGS
|
||||||
start_time = omp_get_wtime();
|
start_time = clock();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
forward_propagation(network);
|
forward_propagation(network);
|
||||||
|
|
||||||
#ifdef DETAILED_TRAIN_TIMINGS
|
#ifdef DETAILED_TRAIN_TIMINGS
|
||||||
printf("Temps de forward: ");
|
printf("Temps de forward: ");
|
||||||
printf_time(omp_get_wtime() - start_time);
|
printf_time(clock() - start_time);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
start_time = omp_get_wtime();
|
start_time = clock();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
maxi = indice_max(network->input[network->size-1][0][0], 10);
|
maxi = indice_max(network->input[network->size-1][0][0], 10);
|
||||||
@ -108,9 +108,9 @@ void* train_thread(void* parameters) {
|
|||||||
|
|
||||||
#ifdef DETAILED_TRAIN_TIMINGS
|
#ifdef DETAILED_TRAIN_TIMINGS
|
||||||
printf("Temps de backward: ");
|
printf("Temps de backward: ");
|
||||||
printf_time(omp_get_wtime() - start_time);
|
printf_time(clock() - start_time);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
start_time = omp_get_wtime();
|
start_time = clock();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (maxi == labels[index[i]]) {
|
if (maxi == labels[index[i]]) {
|
||||||
@ -131,16 +131,16 @@ void* train_thread(void* parameters) {
|
|||||||
write_256_image_in_network(param->dataset->images[index[i]], width, height, param->dataset->numComponents, network->width[0], network->input[0]);
|
write_256_image_in_network(param->dataset->images[index[i]], width, height, param->dataset->numComponents, network->width[0], network->input[0]);
|
||||||
|
|
||||||
#ifdef DETAILED_TRAIN_TIMINGS
|
#ifdef DETAILED_TRAIN_TIMINGS
|
||||||
start_time = omp_get_wtime();
|
start_time = clock();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
forward_propagation(network);
|
forward_propagation(network);
|
||||||
|
|
||||||
#ifdef DETAILED_TRAIN_TIMINGS
|
#ifdef DETAILED_TRAIN_TIMINGS
|
||||||
printf("Temps de forward: ");
|
printf("Temps de forward: ");
|
||||||
printf_time(omp_get_wtime() - start_time);
|
printf_time(clock() - start_time);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
start_time = omp_get_wtime();
|
start_time = clock();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
maxi = indice_max(network->input[network->size-1][0][0], param->dataset->numCategories);
|
maxi = indice_max(network->input[network->size-1][0][0], param->dataset->numCategories);
|
||||||
@ -148,9 +148,9 @@ void* train_thread(void* parameters) {
|
|||||||
|
|
||||||
#ifdef DETAILED_TRAIN_TIMINGS
|
#ifdef DETAILED_TRAIN_TIMINGS
|
||||||
printf("Temps de backward: ");
|
printf("Temps de backward: ");
|
||||||
printf_time(omp_get_wtime() - start_time);
|
printf_time(clock() - start_time);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
start_time = omp_get_wtime();
|
start_time = clock();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
srand(time(NULL));
|
srand(clock());
|
||||||
float loss;
|
float loss;
|
||||||
float batch_loss; // May be redundant with loss, but gives more informations
|
float batch_loss; // May be redundant with loss, but gives more informations
|
||||||
float test_accuracy = 0.; // Used to decrease Learning rate
|
float test_accuracy = 0.; // Used to decrease Learning rate
|
||||||
@ -190,12 +190,12 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
|
|||||||
|
|
||||||
|
|
||||||
//* Différents timers pour mesurer les performance en terme de vitesse
|
//* Différents timers pour mesurer les performance en terme de vitesse
|
||||||
double start_time, end_time;
|
clock_t start_time, end_time;
|
||||||
double elapsed_time;
|
clock_t elapsed_time;
|
||||||
|
|
||||||
double algo_start = omp_get_wtime();
|
clock_t algo_start = clock();
|
||||||
|
|
||||||
start_time = omp_get_wtime();
|
start_time = clock();
|
||||||
|
|
||||||
|
|
||||||
//* Chargement du dataset
|
//* Chargement du dataset
|
||||||
@ -320,7 +320,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
|
|||||||
train_params->finetuning = finetuning;
|
train_params->finetuning = finetuning;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
end_time = omp_get_wtime();
|
end_time = clock();
|
||||||
|
|
||||||
elapsed_time = end_time - start_time;
|
elapsed_time = end_time - start_time;
|
||||||
printf("Taux d'apprentissage initial: %0.2e\n", network->learning_rate);
|
printf("Taux d'apprentissage initial: %0.2e\n", network->learning_rate);
|
||||||
@ -331,7 +331,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
|
|||||||
//* Boucle d'apprentissage
|
//* Boucle d'apprentissage
|
||||||
for (int i=0; i < epochs; i++) {
|
for (int i=0; i < epochs; i++) {
|
||||||
|
|
||||||
start_time = omp_get_wtime();
|
start_time = clock();
|
||||||
// La variable accuracy permet d'avoir une ESTIMATION
|
// La variable accuracy permet d'avoir une ESTIMATION
|
||||||
// du taux de réussite et de l'entraînement du réseau,
|
// du taux de réussite et de l'entraînement du réseau,
|
||||||
// mais n'est en aucun cas une valeur réelle dans le cas
|
// mais n'est en aucun cas une valeur réelle dans le cas
|
||||||
@ -423,7 +423,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
//* Fin d'une époque: affichage des résultats et sauvegarde du réseau
|
//* Fin d'une époque: affichage des résultats et sauvegarde du réseau
|
||||||
end_time = omp_get_wtime();
|
end_time = clock();
|
||||||
elapsed_time = end_time - start_time;
|
elapsed_time = end_time - start_time;
|
||||||
#ifdef USE_MULTITHREADING
|
#ifdef USE_MULTITHREADING
|
||||||
printf("\rThreads [%d]\tÉpoque [%d/%d]\tImage [%d/%d]\tAccuracy: " GREEN "%0.4f%%" RESET " \tLoss: %lf\tTemps: ", nb_threads, i, epochs, nb_images_total, nb_images_total, accuracy*100, loss);
|
printf("\rThreads [%d]\tÉpoque [%d/%d]\tImage [%d/%d]\tAccuracy: " GREEN "%0.4f%%" RESET " \tLoss: %lf\tTemps: ", nb_threads, i, epochs, nb_images_total, nb_images_total, accuracy*100, loss);
|
||||||
@ -483,7 +483,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di
|
|||||||
free_dataset(dataset);
|
free_dataset(dataset);
|
||||||
}
|
}
|
||||||
|
|
||||||
end_time = omp_get_wtime();
|
end_time = clock();
|
||||||
elapsed_time = end_time - algo_start;
|
elapsed_time = end_time - algo_start;
|
||||||
printf("\nTemps total: ");
|
printf("\nTemps total: ");
|
||||||
printf_time(elapsed_time);
|
printf_time(elapsed_time);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "include/colors.h"
|
#include "include/colors.h"
|
||||||
|
|
||||||
@ -15,11 +16,13 @@ void printf_info(char* string) {
|
|||||||
printf(BOLDBLUE "[ INFO ]" RESET " %s", string);
|
printf(BOLDBLUE "[ INFO ]" RESET " %s", string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printf_time(float time) {
|
void printf_time(clock_t time) {
|
||||||
int hours = time/3600;
|
double real_time = (double) time / CLOCKS_PER_SEC;
|
||||||
int minutes = ((int)time %3600)/60;
|
|
||||||
int seconds = ((int)time) %60;
|
int hours = real_time/3600;
|
||||||
int milliseconds = (time - (int)time)*1000;
|
int minutes = ((int)real_time %3600)/60;
|
||||||
|
int seconds = ((int)real_time) %60;
|
||||||
|
int milliseconds = (real_time - (int)real_time)*1000;
|
||||||
|
|
||||||
if (hours != 0) {
|
if (hours != 0) {
|
||||||
printf("%dh %dmn", hours, minutes);
|
printf("%dh %dmn", hours, minutes);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#ifndef DEF_COLORS_H
|
#ifndef DEF_COLORS_H
|
||||||
#define DEF_COLORS_H
|
#define DEF_COLORS_H
|
||||||
@ -51,7 +52,7 @@ extern "C"
|
|||||||
/*
|
/*
|
||||||
* Affiche un timing en heures minutes secondes millisecondes en limitant la précision aux deux unités les plus significatives
|
* Affiche un timing en heures minutes secondes millisecondes en limitant la précision aux deux unités les plus significatives
|
||||||
*/
|
*/
|
||||||
void printf_time(float time);
|
void printf_time(clock_t time);
|
||||||
|
|
||||||
#ifdef __CUDACC__
|
#ifdef __CUDACC__
|
||||||
extern "C"
|
extern "C"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <omp.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "../src/common/include/memory_management.h"
|
#include "../src/common/include/memory_management.h"
|
||||||
#include "../src/cnn/include/convolution.h"
|
#include "../src/cnn/include/convolution.h"
|
||||||
@ -136,21 +136,21 @@ void run_convolution_test(int input_width, int output_width, int rows, int colum
|
|||||||
|
|
||||||
|
|
||||||
// Lancement des calculs
|
// Lancement des calculs
|
||||||
double start_time, end_time;
|
clock_t start_time, end_time;
|
||||||
double cpu_time_used, gpu_time_used;
|
clock_t cpu_time_used, gpu_time_used;
|
||||||
|
|
||||||
start_time = omp_get_wtime();
|
start_time = clock();
|
||||||
make_convolution_device(kernel, input, output_gpu, output_width, 1, 0);
|
make_convolution_device(kernel, input, output_gpu, output_width, 1, 0);
|
||||||
end_time = omp_get_wtime();
|
end_time = clock();
|
||||||
|
|
||||||
|
|
||||||
gpu_time_used = end_time - start_time;
|
gpu_time_used = end_time - start_time;
|
||||||
printf("(%d, %d, %d, %d) Time used for GPU: %lf seconds\n", rows, columns, input_width, output_width, gpu_time_used);
|
printf("(%d, %d, %d, %d) Time used for GPU: %lf seconds\n", rows, columns, input_width, output_width, gpu_time_used);
|
||||||
|
|
||||||
|
|
||||||
start_time = omp_get_wtime();
|
start_time = clock();
|
||||||
make_convolution_cpu(kernel, input, output_cpu, output_width, 1, 0);
|
make_convolution_cpu(kernel, input, output_cpu, output_width, 1, 0);
|
||||||
end_time = omp_get_wtime();
|
end_time = clock();
|
||||||
|
|
||||||
cpu_time_used = end_time - start_time;
|
cpu_time_used = end_time - start_time;
|
||||||
printf("(%d, %d, %d, %d) Time used for CPU: %lf seconds\n", rows, columns, input_width, output_width, cpu_time_used);
|
printf("(%d, %d, %d, %d) Time used for CPU: %lf seconds\n", rows, columns, input_width, output_width, cpu_time_used);
|
||||||
@ -199,7 +199,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
printf(GREEN "OK\n" RESET);
|
printf(GREEN "OK\n" RESET);
|
||||||
|
|
||||||
srand(time(NULL));
|
srand(clock());
|
||||||
|
|
||||||
run_convolution_test(20, 15, 30, 40);
|
run_convolution_test(20, 15, 30, 40);
|
||||||
run_convolution_test(30, 25, 40, 50);
|
run_convolution_test(30, 25, 40, 50);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <omp.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
|
||||||
#include "../src/common/include/colors.h"
|
#include "../src/common/include/colors.h"
|
||||||
@ -21,10 +21,10 @@ int main(int argc, char* argv[]) {
|
|||||||
printf("Taille des images: %dx%d\n", dataset->width, dataset->height);
|
printf("Taille des images: %dx%d\n", dataset->width, dataset->height);
|
||||||
|
|
||||||
// Calcul du temps de chargement des images une à une
|
// Calcul du temps de chargement des images une à une
|
||||||
double start_time, end_time;
|
clock_t start_time, end_time;
|
||||||
|
|
||||||
int N = min(100000, dataset->numImages);
|
int N = min(100000, dataset->numImages);
|
||||||
start_time = omp_get_wtime();
|
start_time = clock();
|
||||||
printf("Chargement de %d images\n", N);
|
printf("Chargement de %d images\n", N);
|
||||||
for (int i=0; i < N; i++) {
|
for (int i=0; i < N; i++) {
|
||||||
imgRawImage* image = loadJpegImageFile(dataset->fileNames[i]);
|
imgRawImage* image = loadJpegImageFile(dataset->fileNames[i]);
|
||||||
@ -32,7 +32,7 @@ int main(int argc, char* argv[]) {
|
|||||||
free(image);
|
free(image);
|
||||||
}
|
}
|
||||||
printf("OK\n");
|
printf("OK\n");
|
||||||
end_time = omp_get_wtime();
|
end_time = clock();
|
||||||
printf("Temps par image (calculé sur une moyenne de %d): %lf s\n", N, (end_time - start_time)/N);
|
printf("Temps par image (calculé sur une moyenne de %d): %lf s\n", N, (end_time - start_time)/N);
|
||||||
|
|
||||||
for (int i=0; i < (int)dataset->numImages; i++) {
|
for (int i=0; i < (int)dataset->numImages; i++) {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <omp.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "../src/cnn/include/matrix_multiplication.h"
|
#include "../src/cnn/include/matrix_multiplication.h"
|
||||||
#include "../src/common/include/memory_management.h"
|
#include "../src/common/include/memory_management.h"
|
||||||
@ -72,8 +72,8 @@ bool check_matrices_equality(float** m1, float** m2, int n, int p, int acceptati
|
|||||||
}
|
}
|
||||||
|
|
||||||
void run_matrices_test(int n, int p, int q) {
|
void run_matrices_test(int n, int p, int q) {
|
||||||
double start_time, end_time;
|
clock_t start_time, end_time;
|
||||||
double cpu_time_used, gpu_time_used;
|
clock_t cpu_time_used, gpu_time_used;
|
||||||
|
|
||||||
float** matrix1 = create_matrix(n, p);
|
float** matrix1 = create_matrix(n, p);
|
||||||
float** matrix2 = create_matrix(p, q);
|
float** matrix2 = create_matrix(p, q);
|
||||||
@ -81,16 +81,16 @@ void run_matrices_test(int n, int p, int q) {
|
|||||||
float** result_cpu = create_empty_matrix(n, q);
|
float** result_cpu = create_empty_matrix(n, q);
|
||||||
|
|
||||||
printf("(%d,%d)x(%d,%d) Data generation complete.\n", n, p, p, q);
|
printf("(%d,%d)x(%d,%d) Data generation complete.\n", n, p, p, q);
|
||||||
start_time = omp_get_wtime();
|
start_time = clock();
|
||||||
matrix_multiplication_device(matrix1, matrix2, result_gpu, n, p, q);
|
matrix_multiplication_device(matrix1, matrix2, result_gpu, n, p, q);
|
||||||
end_time = omp_get_wtime();
|
end_time = clock();
|
||||||
|
|
||||||
cpu_time_used = end_time - start_time;
|
cpu_time_used = end_time - start_time;
|
||||||
printf("(%d,%d)x(%d,%d) Time used for GPU: %lf seconds\n", n, p, p, q, cpu_time_used);
|
printf("(%d,%d)x(%d,%d) Time used for GPU: %lf seconds\n", n, p, p, q, cpu_time_used);
|
||||||
|
|
||||||
start_time = omp_get_wtime();
|
start_time = clock();
|
||||||
matrix_multiplication_host(matrix1, matrix2, result_cpu, n, p, q);
|
matrix_multiplication_host(matrix1, matrix2, result_cpu, n, p, q);
|
||||||
end_time = omp_get_wtime();
|
end_time = clock();
|
||||||
|
|
||||||
gpu_time_used = end_time - start_time;
|
gpu_time_used = end_time - start_time;
|
||||||
printf("(%d,%d)x(%d,%d) Time used for CPU: %lf seconds\n", n, p, p, q, gpu_time_used);
|
printf("(%d,%d)x(%d,%d) Time used for CPU: %lf seconds\n", n, p, p, q, gpu_time_used);
|
||||||
@ -134,7 +134,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
printf(GREEN "OK\n" RESET);
|
printf(GREEN "OK\n" RESET);
|
||||||
|
|
||||||
srand(time(NULL));
|
srand(clock());
|
||||||
run_matrices_test(200, 1000, 200);
|
run_matrices_test(200, 1000, 200);
|
||||||
run_matrices_test(200, 1000, 20);
|
run_matrices_test(200, 1000, 20);
|
||||||
run_matrices_test(20, 1000, 200);
|
run_matrices_test(20, 1000, 200);
|
||||||
|
Loading…
Reference in New Issue
Block a user