Compare commits

..

No commits in common. "dbd5362d7ddd37a8ad00ff68cb707b4a7fcd6af4" and "4625ad29923dc7010eb8dac93c74684615f2b9f8" have entirely different histories.

11 changed files with 39 additions and 98 deletions

View File

@ -181,7 +181,6 @@ void free_network(Network* network) {
// et que cela soit le cas UNIQUEMENT pour la mémoire allouée au réseau // et que cela soit le cas UNIQUEMENT pour la mémoire allouée au réseau
// Représente un gain de 45mn sur VGG16 // Représente un gain de 45mn sur VGG16
(void)network;
free_all_memory(); free_all_memory();
#else #else
for (int i=network->size-2; i>=0; i--) { for (int i=network->size-2; i>=0; i--) {

View File

@ -1,8 +1,7 @@
#include <stdbool.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "../common/include/memory_management.h" #include "../common/include/memory_management.h"
#include "../common/include/mnist.h" #include "../common/include/mnist.h"
@ -184,13 +183,12 @@ void recognize_mnist(Network* network, char* input_file, char* out) {
} }
void recognize_jpg(Network* network, char* input_file, char* out) { void recognize_jpg(Network* network, char* input_file, char* out) {
int width; // Dimensions de l'image, qui doit être carrée int width, height; // Dimensions de l'image
int maxi; int maxi;
imgRawImage* image = loadJpegImageFile(input_file); imgRawImage* image = loadJpegImageFile(input_file);
width = image->width; width = image->width;
height = image->height;
assert(image->width == image->height);
if (! strcmp(out, "json")) { if (! strcmp(out, "json")) {
printf("{\n"); printf("{\n");

View File

@ -127,7 +127,7 @@ void* train_thread(void* parameters) {
void train(int dataset_type, char* images_file, char* labels_file, char* data_dir, int epochs, char* out, char* recover) { void train(int dataset_type, char* images_file, char* labels_file, char* data_dir, int epochs, char* out, char* recover) {
#ifdef USE_CUDA #ifdef USE_CUDA
bool compatibility = cuda_setup(true); bool compatibility = check_cuda_compatibility();
if (!compatibility) { if (!compatibility) {
printf("Exiting.\n"); printf("Exiting.\n");
exit(1); exit(1);

View File

@ -60,10 +60,8 @@ extern "C"
#endif #endif
/* /*
* Vérification de la compatibilité CUDA * Vérification de la compatibilité CUDA
* spécifier avec "verbose" si il faut afficher
* la carte utilisée notamment
*/ */
bool cuda_setup(bool verbose); bool check_cuda_compatibility();
#ifdef __CUDACC__ #ifdef __CUDACC__
extern "C" extern "C"

View File

@ -1,7 +1,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#ifdef USE_CUDA #ifdef USE_CUDA
#ifndef __CUDACC__ #ifndef __CUDACC__
#include "cuda_runtime.h" #include "cuda_runtime.h"
@ -43,65 +42,39 @@ int i_div_up(int a, int b) { // Partie entière supérieure de a/b
#ifdef __CUDACC__ #ifdef __CUDACC__
extern "C" extern "C"
#endif #endif
bool cuda_setup(bool verbose) { bool check_cuda_compatibility() {
#ifdef __CUDACC__ #ifdef __CUDACC__
int nDevices; int nDevices;
int selected_device = 0;
cudaDeviceProp selected_prop;
cudaDeviceProp prop; cudaDeviceProp prop;
cudaGetDeviceCount(&nDevices); cudaGetDeviceCount(&nDevices);
if (nDevices <= 0) { // I've seen weird issues when there is no GPU at all if (nDevices == 0) {
if (verbose) { printf("Pas d'utilisation du GPU\n\n");
printf("Pas d'utilisation du GPU\n\n");
}
return false; return false;
} }
if (verbose) { printf("GPUs disponibles:\n");
printf("GPUs disponibles:\n");
}
cudaGetDeviceProperties(&selected_prop, selected_device);
for (int i=0; i < nDevices; i++) { for (int i=0; i < nDevices; i++) {
cudaGetDeviceProperties(&prop, i); cudaGetDeviceProperties(&prop, i);
printf(" - %s\n\t - Compute Capability: %d.%d\n\t - Memory available: ", prop.name, prop.major, prop.minor);
if (verbose) { printf_memory(prop.totalGlobalMem);
printf(" - %s\n\t - Compute Capability: %d.%d\n\t - Memory available: ", prop.name, prop.major, prop.minor); printf("\n\t - Shared Memory per block: ");
printf_memory(prop.totalGlobalMem); printf_memory(prop.sharedMemPerBlock);
printf("\n\t - Shared Memory per block: "); printf("\n\n");
printf_memory(prop.sharedMemPerBlock);
printf("\n\n");
}
if (prop.clockRate*prop.multiProcessorCount >= selected_prop.clockRate*selected_prop.multiProcessorCount) { // This criteria approximately matches the best device
selected_prop = prop;
selected_device = i;
}
} }
cudaSetDevice(selected_device); // Select the best device for computation cudaGetDeviceProperties(&prop, 0);
if (verbose) { printf("Utilisation du GPU: " BLUE "%s" RESET "\n\n", prop.name);
printf("Utilisation du GPU: " BLUE "%s" RESET "\n\n", selected_prop.name);
}
if (BLOCKSIZE_x*BLOCKSIZE_y*BLOCKSIZE_z > prop.maxThreadsPerBlock) { if (prop.sharedMemPerBlock != MEMORY_BLOCK) {
printf_error((char*)"La taille de bloc sélectionnée est trop grande.\n");
printf("\tMaximum accepté: %d\n", selected_prop.maxThreadsPerBlock);
exit(1);
}
if (selected_prop.sharedMemPerBlock != MEMORY_BLOCK) { // C'est un warning, on l'affiche dans tous les cas
printf_warning((char*)"La taille des blocs mémoire du GPU et celle utilisée dans le code diffèrent.\n"); printf_warning((char*)"La taille des blocs mémoire du GPU et celle utilisée dans le code diffèrent.\n");
printf("\tCela peut mener à une utilisation supplémentaire de VRAM.\n"); printf("\tCela peut mener à une utilisation supplémentaire de VRAM.\n");
printf("\tChanger MEMORY_BLOCK à %ld dans src/include/memory_management.h\n", selected_prop.sharedMemPerBlock); printf("\tChanger MEMORY_BLOCK à %ld dans src/include/memory_management.h\n", prop.sharedMemPerBlock);
} }
return true; return true;
#else #else
if (verbose) { printf("Pas d'utilisation du GPU\n\n");
printf("Pas d'utilisation du GPU\n\n");
}
return false; return false;
#endif #endif
} }

View File

@ -1,7 +1,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#ifdef USE_CUDA #ifdef USE_CUDA
#ifndef __CUDACC__ #ifndef __CUDACC__
#include "cuda_runtime.h" #include "cuda_runtime.h"
@ -43,65 +42,39 @@ int i_div_up(int a, int b) { // Partie entière supérieure de a/b
#ifdef __CUDACC__ #ifdef __CUDACC__
extern "C" extern "C"
#endif #endif
bool cuda_setup(bool verbose) { bool check_cuda_compatibility() {
#ifdef __CUDACC__ #ifdef __CUDACC__
int nDevices; int nDevices;
int selected_device = 0;
cudaDeviceProp selected_prop;
cudaDeviceProp prop; cudaDeviceProp prop;
cudaGetDeviceCount(&nDevices); cudaGetDeviceCount(&nDevices);
if (nDevices <= 0) { // I've seen weird issues when there is no GPU at all if (nDevices == 0) {
if (verbose) { printf("Pas d'utilisation du GPU\n\n");
printf("Pas d'utilisation du GPU\n\n");
}
return false; return false;
} }
if (verbose) { printf("GPUs disponibles:\n");
printf("GPUs disponibles:\n");
}
cudaGetDeviceProperties(&selected_prop, selected_device);
for (int i=0; i < nDevices; i++) { for (int i=0; i < nDevices; i++) {
cudaGetDeviceProperties(&prop, i); cudaGetDeviceProperties(&prop, i);
printf(" - %s\n\t - Compute Capability: %d.%d\n\t - Memory available: ", prop.name, prop.major, prop.minor);
if (verbose) { printf_memory(prop.totalGlobalMem);
printf(" - %s\n\t - Compute Capability: %d.%d\n\t - Memory available: ", prop.name, prop.major, prop.minor); printf("\n\t - Shared Memory per block: ");
printf_memory(prop.totalGlobalMem); printf_memory(prop.sharedMemPerBlock);
printf("\n\t - Shared Memory per block: "); printf("\n\n");
printf_memory(prop.sharedMemPerBlock);
printf("\n\n");
}
if (prop.clockRate*prop.multiProcessorCount >= selected_prop.clockRate*selected_prop.multiProcessorCount) { // This criteria approximately matches the best device
selected_prop = prop;
selected_device = i;
}
} }
cudaSetDevice(selected_device); // Select the best device for computation cudaGetDeviceProperties(&prop, 0);
if (verbose) { printf("Utilisation du GPU: " BLUE "%s" RESET "\n\n", prop.name);
printf("Utilisation du GPU: " BLUE "%s" RESET "\n\n", selected_prop.name);
}
if (BLOCKSIZE_x*BLOCKSIZE_y*BLOCKSIZE_z > prop.maxThreadsPerBlock) { if (prop.sharedMemPerBlock != MEMORY_BLOCK) {
printf_error((char*)"La taille de bloc sélectionnée est trop grande.\n");
printf("\tMaximum accepté: %d\n", selected_prop.maxThreadsPerBlock);
exit(1);
}
if (selected_prop.sharedMemPerBlock != MEMORY_BLOCK) { // C'est un warning, on l'affiche dans tous les cas
printf_warning((char*)"La taille des blocs mémoire du GPU et celle utilisée dans le code diffèrent.\n"); printf_warning((char*)"La taille des blocs mémoire du GPU et celle utilisée dans le code diffèrent.\n");
printf("\tCela peut mener à une utilisation supplémentaire de VRAM.\n"); printf("\tCela peut mener à une utilisation supplémentaire de VRAM.\n");
printf("\tChanger MEMORY_BLOCK à %ld dans src/include/memory_management.h\n", selected_prop.sharedMemPerBlock); printf("\tChanger MEMORY_BLOCK à %ld dans src/include/memory_management.h\n", prop.sharedMemPerBlock);
} }
return true; return true;
#else #else
if (verbose) { printf("Pas d'utilisation du GPU\n\n");
printf("Pas d'utilisation du GPU\n\n");
}
return false; return false;
#endif #endif
} }

View File

@ -217,7 +217,7 @@ int main(int argc, char* argv[]) {
/* /*
printf("Checking CUDA compatibility.\n"); printf("Checking CUDA compatibility.\n");
bool cuda_compatible = cuda_setup(true); bool cuda_compatible = check_cuda_compatibility();
if (!cuda_compatible) { if (!cuda_compatible) {
printf(RED "CUDA not compatible, skipping tests.\n" RESET); printf(RED "CUDA not compatible, skipping tests.\n" RESET);
return 0; return 0;

View File

@ -192,7 +192,7 @@ void run_convolution_test(int input_width, int output_width, int rows, int colum
int main() { int main() {
printf("Checking CUDA compatibility.\n"); printf("Checking CUDA compatibility.\n");
bool cuda_compatible = cuda_setup(true); bool cuda_compatible = check_cuda_compatibility();
if (!cuda_compatible) { if (!cuda_compatible) {
printf(RED "CUDA not compatible, skipping tests.\n" RESET); printf(RED "CUDA not compatible, skipping tests.\n" RESET);
return 0; return 0;

View File

@ -91,7 +91,7 @@ void test1(int activation, bool use_local_kernel) {
int main() { int main() {
printf("Checking CUDA compatibility.\n"); printf("Checking CUDA compatibility.\n");
bool cuda_compatible = cuda_setup(true); bool cuda_compatible = check_cuda_compatibility();
if (!cuda_compatible) { if (!cuda_compatible) {
printf(RED "CUDA not compatible, skipping tests.\n" RESET); printf(RED "CUDA not compatible, skipping tests.\n" RESET);
return 0; return 0;

View File

@ -127,7 +127,7 @@ void run_matrices_test(int n, int p, int q) {
int main() { int main() {
printf("Checking CUDA compatibility.\n"); printf("Checking CUDA compatibility.\n");
bool cuda_compatible = cuda_setup(true); bool cuda_compatible = check_cuda_compatibility();
if (!cuda_compatible) { if (!cuda_compatible) {
printf(RED "CUDA not compatible, skipping tests.\n" RESET); printf(RED "CUDA not compatible, skipping tests.\n" RESET);
return 0; return 0;

View File

@ -18,7 +18,7 @@ __global__ void check_access(int* array, int range) {
int main() { int main() {
printf("Checking CUDA compatibility.\n"); printf("Checking CUDA compatibility.\n");
bool cuda_compatible = cuda_setup(true); bool cuda_compatible = check_cuda_compatibility();
if (!cuda_compatible) { if (!cuda_compatible) {
printf(RED "CUDA not compatible, skipping tests.\n" RESET); printf(RED "CUDA not compatible, skipping tests.\n" RESET);
return 0; return 0;