From f27d7542f8245695a748c662e5ba289f3882c886 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Wed, 1 Jun 2022 17:13:45 +0200 Subject: [PATCH] Add cuda_utils --- src/mnist/cuda_utils.cu | 29 +++++++++++++++++++++++++++++ src/mnist/include/cuda_utils.h | 10 ++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/mnist/cuda_utils.cu create mode 100644 src/mnist/include/cuda_utils.h diff --git a/src/mnist/cuda_utils.cu b/src/mnist/cuda_utils.cu new file mode 100644 index 0000000..b1503c3 --- /dev/null +++ b/src/mnist/cuda_utils.cu @@ -0,0 +1,29 @@ +#include +#include + + +int*** copy_images_cuda(int*** images, int nb_images, int width, int height) { + int*** images_cuda; + cudaMalloc((int****)&images_cuda, sizeof(int**)*nb_images); + cudaMemcpy((int****)&images_cuda, sizeof(int**)*nb_images, images); + + for (int i=0; i < nb_images; i++) { + cudaMalloc((int***)&images_cuda[i], sizeof(int**)*nb_images); + cudaMemcpy((int***)&images_cuda[i], sizeof(int**)*nb_images, images[i]); + for (int j=0; j < height; j++) { + cudaMalloc((int**)&images_cuda[i][j], sizeof(int*)*width); + cudaMemcpy((int**)&images_cuda[i][j], sizeof(int*)*width, images[i][j]); + } + } + return images_cuda; +} + + + + +unsigned int* copy_labels_cuda(unsigned int* labels) { + unsigned int* labels_cuda; + cudaMalloc((unsigned int**)&labels_cuda, sizeof(labels)); + cudaMemcpy((unsigned int**)&labels_cuda, sizeof(labels), labels); + return labels_cuda; +} \ No newline at end of file diff --git a/src/mnist/include/cuda_utils.h b/src/mnist/include/cuda_utils.h new file mode 100644 index 0000000..cce1786 --- /dev/null +++ b/src/mnist/include/cuda_utils.h @@ -0,0 +1,10 @@ +#include +#include + +#ifndef DEF_CUDA_UTILS_H +#define DEF_CUDA_UTILS_H + +int*** copy_images_cuda(int*** images, int nb_images, int width, int height); +unsigned int* copy_labels_cuda(unsigned int* labels); + +#endif \ No newline at end of file