diff --git a/src/cnn/creation.c b/src/cnn/creation.c index 2c261ad..4cdb41a 100644 --- a/src/cnn/creation.c +++ b/src/cnn/creation.c @@ -1,6 +1,7 @@ #include #include +#include "../include/memory_management.h" #include "include/initialisation.h" #include "include/function.h" #include "../include/utils.h" diff --git a/src/cnn/free.c b/src/cnn/free.c index 9595812..e0ce7bf 100644 --- a/src/cnn/free.c +++ b/src/cnn/free.c @@ -1,7 +1,7 @@ #include #include -#include "../include/utils.h" +#include "../include/memory_management.h" #include "include/free.h" @@ -103,8 +103,9 @@ void free_dense_linearisation(Network* network, int pos) { void free_network_creation(Network* network) { free_a_cube_input_layer(network, 0, network->depth[0], network->width[0]); - for (int i=0; i < network->max_size-1; i++) + for (int i=0; i < network->max_size-1; i++) { gree(network->kernel[i]); + } gree(network->width); gree(network->depth); gree(network->kernel); diff --git a/src/cnn/jpeg.c b/src/cnn/jpeg.c index 6df0f98..cbcf7e7 100644 --- a/src/cnn/jpeg.c +++ b/src/cnn/jpeg.c @@ -53,9 +53,9 @@ imgRawImage* loadJpegImageFile(char* lpFilename) { #endif dwBufferBytes = imgWidth * imgHeight * 3; /* We only read RGB, not A */ - lpData = (unsigned char*)nalloc(sizeof(unsigned char)*dwBufferBytes); + lpData = (unsigned char*)malloc(sizeof(unsigned char)*dwBufferBytes); - lpNewImage = (imgRawImage*)nalloc(sizeof(imgRawImage)); + lpNewImage = (imgRawImage*)malloc(sizeof(imgRawImage)); lpNewImage->numComponents = numComponents; lpNewImage->width = imgWidth; lpNewImage->height = imgHeight; @@ -75,7 +75,7 @@ imgRawImage* loadJpegImageFile(char* lpFilename) { } jpegDataset* loadJpegDataset(char* folderPath) { - jpegDataset* dataset = (jpegDataset*)nalloc(sizeof(jpegDataset)); + jpegDataset* dataset = (jpegDataset*)malloc(sizeof(jpegDataset)); imgRawImage* image; // We start by counting the number of images and categories @@ -83,8 +83,8 @@ jpegDataset* loadJpegDataset(char* folderPath) { dataset->numImages = countFiles(folderPath); dataset->images = NULL; - dataset->labels = (unsigned int*)nalloc(sizeof(unsigned int)*dataset->numImages); - dataset->fileNames = (char**)nalloc(sizeof(char*)*dataset->numImages); + dataset->labels = (unsigned int*)malloc(sizeof(unsigned int)*dataset->numImages); + dataset->fileNames = (char**)malloc(sizeof(char*)*dataset->numImages); DIR* dirp; struct dirent* entry; @@ -97,17 +97,17 @@ jpegDataset* loadJpegDataset(char* folderPath) { if (strcmp(entry->d_name, ".")&&strcmp(entry->d_name, "..")) { if (entry->d_type == DT_DIR) { prev_index = index; - concatenated_path = nalloc(strlen(folderPath)+strlen(entry->d_name)+2); + concatenated_path = malloc(strlen(folderPath)+strlen(entry->d_name)+2); sprintf(concatenated_path, "%s/%s", folderPath, entry->d_name); addFilenamesToArray(concatenated_path, dataset->fileNames, &index); for (int i=prev_index; i < index; i++) { dataset->labels[i] = getLabel(entry->d_name); } - gree(concatenated_path); + free(concatenated_path); } } } - dataset->images = (unsigned char**)nalloc(sizeof(unsigned char*)*dataset->numImages); + dataset->images = (unsigned char**)malloc(sizeof(unsigned char*)*dataset->numImages); for (int i=0; i < (int)dataset->numImages; i++) { dataset->images[i] = NULL; #ifdef STORE_IMAGES_TO_RAM @@ -117,7 +117,7 @@ jpegDataset* loadJpegDataset(char* folderPath) { } image = loadJpegImageFile(dataset->fileNames[i]); dataset->images[i] = image->lpData; - gree(image); + free(image); #endif } #ifdef STORE_IMAGES_TO_RAM @@ -130,8 +130,8 @@ jpegDataset* loadJpegDataset(char* folderPath) { dataset->height = image->height; dataset->numComponents = image->numComponents; - gree(image->lpData); - gree(image); + free(image->lpData); + free(image); closedir(dirp); return dataset; @@ -185,7 +185,7 @@ void addFilenamesToArray(char* path, char** array, int* index) { dirp = opendir(path); /* There should be error handling after this */ while ((entry = readdir(dirp)) != NULL) { if (entry->d_type == DT_REG) { /* If the entry is a regular file */ - filename = (char*)nalloc(strlen(path)+strlen(entry->d_name)+2); + filename = (char*)malloc(strlen(path)+strlen(entry->d_name)+2); sprintf(filename, "%s/%s", path, entry->d_name); array[i] = filename; i++; @@ -197,15 +197,15 @@ void addFilenamesToArray(char* path, char** array, int* index) { void free_dataset(jpegDataset* dataset) { for (int i=0; i < (int)dataset->numImages; i++) { - gree(dataset->fileNames[i]); + free(dataset->fileNames[i]); #ifdef STORE_IMAGES_TO_RAM - gree(dataset->images[i]); + free(dataset->images[i]); #endif } - gree(dataset->fileNames); - gree(dataset->labels); - gree(dataset->images); - gree(dataset); + free(dataset->fileNames); + free(dataset->labels); + free(dataset->images); + free(dataset); } unsigned int getLabel(char* string) { diff --git a/src/cnn/neuron_io.c b/src/cnn/neuron_io.c index f42a605..987e19b 100644 --- a/src/cnn/neuron_io.c +++ b/src/cnn/neuron_io.c @@ -3,8 +3,8 @@ #include #include +#include "../include/memory_management.h" #include "../include/colors.h" -#include "../include/utils.h" #include "include/function.h" #include "include/struct.h" diff --git a/src/cnn/preview.c b/src/cnn/preview.c index 2256eae..a4a120e 100644 --- a/src/cnn/preview.c +++ b/src/cnn/preview.c @@ -38,11 +38,11 @@ void preview_images(char* path, int limit) { if (!dataset->images[i]) { image = loadJpegImageFile(dataset->fileNames[i]); dataset->images[i] = image->lpData; - gree(image); + free(image); } print_image(dataset->images[i], dataset->height, dataset->width); - gree(dataset->images[i]); + free(dataset->images[i]); } } diff --git a/src/cnn/test_network.c b/src/cnn/test_network.c index 8987797..34e9960 100644 --- a/src/cnn/test_network.c +++ b/src/cnn/test_network.c @@ -3,9 +3,9 @@ #include #include +#include "../include/memory_management.h" #include "../mnist/include/mnist.h" #include "include/neuron_io.h" -#include "../include/utils.h" #include "include/struct.h" #include "include/jpeg.h" #include "include/free.h" diff --git a/src/cnn/train.c b/src/cnn/train.c index 4fcc00b..a7a3e49 100644 --- a/src/cnn/train.c +++ b/src/cnn/train.c @@ -7,6 +7,7 @@ #include #include +#include "../include/memory_management.h" #include "../mnist/include/mnist.h" #include "include/initialisation.h" #include "include/neuron_io.h" @@ -131,7 +132,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di // Chargement des images du set de données MNIST int* parameters = read_mnist_images_parameters(images_file); nb_images_total = parameters[0]; - gree(parameters); + free(parameters); images = read_mnist_images(images_file); labels = read_mnist_labels(labels_file); @@ -199,7 +200,7 @@ void train(int dataset_type, char* images_file, char* labels_file, char* data_di // thread dans l'hypothèse ou le multi-threading n'est pas utilisé. // Cela est utile à des fins de débogage notamment, // où l'utilisation de threads rend vite les choses plus compliquées qu'elles ne le sont. - TrainParameters* train_params = (TrainParameters*)nalloc(sizeof(TrainParameters)); + TrainParameters* train_params = (TrainParameters*)malloc(sizeof(TrainParameters)); train_params->network = network; train_params->dataset_type = dataset_type; diff --git a/test/cnn_convolution.cu b/test/cnn_convolution.cu index 4bfe4db..9341340 100644 --- a/test/cnn_convolution.cu +++ b/test/cnn_convolution.cu @@ -6,6 +6,7 @@ #include #include +#include "../src/include/memory_management.h" #include "../src/cnn/include/convolution.h" #include "../src/cnn/include/struct.h" #include "../src/include/colors.h" diff --git a/test/cnn_matrix_multiplication.cu b/test/cnn_matrix_multiplication.cu index cd322b8..c87fe6d 100644 --- a/test/cnn_matrix_multiplication.cu +++ b/test/cnn_matrix_multiplication.cu @@ -6,6 +6,7 @@ #include #include "../src/cnn/include/matrix_multiplication.h" +#include "../src/include/memory_management.h" #include "../src/include/colors.h" #include "../src/include/utils.h"