Fix cuda compilation

This commit is contained in:
augustin64 2023-05-13 22:42:13 +02:00
parent c0808b9240
commit 321994df2b
7 changed files with 30 additions and 5 deletions

View File

@ -9,6 +9,7 @@
#include "../common/include/utils.h" #include "../common/include/utils.h"
#include "include/backpropagation.h" #include "include/backpropagation.h"
#include "include/initialisation.h" #include "include/initialisation.h"
#include "include/convolution.h"
#include "include/function.h" #include "include/function.h"
#include "include/creation.h" #include "include/creation.h"
#include "include/update.h" #include "include/update.h"

View File

@ -7,7 +7,9 @@
#include "include/config.h" #include "include/config.h"
#ifdef __CUDACC__
__host__ __device__
#endif
int convolution_not_outside(int x, int y, int lower_bound, int upper_bound) { int convolution_not_outside(int x, int y, int lower_bound, int upper_bound) {
return !(x < lower_bound || y < lower_bound || x >= upper_bound || y>= upper_bound); return !(x < lower_bound || y < lower_bound || x >= upper_bound || y>= upper_bound);
} }
@ -86,6 +88,9 @@ void make_convolution_device(Kernel_cnn* kernel, float*** input, float*** output
} }
#endif #endif
#ifdef __CUDACC__
extern "C"
#endif
void make_convolution(Kernel_cnn* kernel, float*** input, float*** output, int output_width, int stride, int padding) { void make_convolution(Kernel_cnn* kernel, float*** input, float*** output, int output_width, int stride, int padding) {
#ifndef __CUDACC__ #ifndef __CUDACC__
make_convolution_cpu(kernel, input, output, output_width, stride, padding); make_convolution_cpu(kernel, input, output, output_width, stride, padding);

View File

@ -7,7 +7,9 @@
#include "include/config.h" #include "include/config.h"
#ifdef __CUDACC__
__host__ __device__
#endif
int convolution_not_outside(int x, int y, int lower_bound, int upper_bound) { int convolution_not_outside(int x, int y, int lower_bound, int upper_bound) {
// On renvoie true si et seulement si _ et _: // On renvoie true si et seulement si _ et _:
// lower_bound <= x < upper_bound // lower_bound <= x < upper_bound
@ -90,6 +92,9 @@ void make_convolution_device(Kernel_cnn* kernel, float*** input, float*** output
} }
#endif #endif
#ifdef __CUDACC__
extern "C"
#endif
void make_convolution(Kernel_cnn* kernel, float*** input, float*** output, int output_width, int stride, int padding) { void make_convolution(Kernel_cnn* kernel, float*** input, float*** output, int output_width, int stride, int padding) {
#ifndef __CUDACC__ #ifndef __CUDACC__
make_convolution_cpu(kernel, input, output, output_width, stride, padding); make_convolution_cpu(kernel, input, output, output_width, stride, padding);

View File

@ -1,5 +1,8 @@
#include "struct.h" #include "struct.h"
#ifdef __CUDACC__
__host__ __device__
#endif
/* /*
On renvoie true si et seulement si _ et _: On renvoie true si et seulement si _ et _:
lower_bound <= x < upper_bound lower_bound <= x < upper_bound
@ -24,6 +27,9 @@ __global__ void make_convolution_kernel(int k_size, int columns, int rows, float
void make_convolution_device(Kernel_cnn* kernel, float*** input, float*** output, int output_width, int stride, int padding); void make_convolution_device(Kernel_cnn* kernel, float*** input, float*** output, int output_width, int stride, int padding);
#endif #endif
#ifdef __CUDACC__
extern "C"
#endif
/* /*
* Détermine si la convolution peut-être faite sur la carte graphique au moment de la compilation * Détermine si la convolution peut-être faite sur la carte graphique au moment de la compilation
*/ */

View File

@ -3,8 +3,10 @@
#ifndef DEF_MAKE_H #ifndef DEF_MAKE_H
#define DEF_MAKE_H #define DEF_MAKE_H
#ifdef __CUDACC__
__host__ __device__
#endif
/* /*
*
* On renvoie true si et seulement si _ et _: * On renvoie true si et seulement si _ et _:
* lower_bound <= y < upper_bound * lower_bound <= y < upper_bound
* lower_bound <= x < upper_bound * lower_bound <= x < upper_bound

View File

@ -10,6 +10,9 @@
#include "include/config.h" #include "include/config.h"
#ifdef __CUDACC__
__host__ __device__
#endif
int pooling_not_outside(int x, int y, int lower_bound, int upper_bound) { int pooling_not_outside(int x, int y, int lower_bound, int upper_bound) {
return !(x < lower_bound || y < lower_bound || x >= upper_bound || y>= upper_bound); return !(x < lower_bound || y < lower_bound || x >= upper_bound || y>= upper_bound);
} }
@ -136,7 +139,7 @@ void make_max_pooling_device(float*** input, float*** output, int size, int outp
dim3 gridSize(i_div_up(output_depth, BLOCKSIZE_x), i_div_up(output_width, BLOCKSIZE_y), i_div_up(output_width, BLOCKSIZE_z)); dim3 gridSize(i_div_up(output_depth, BLOCKSIZE_x), i_div_up(output_width, BLOCKSIZE_y), i_div_up(output_width, BLOCKSIZE_z));
dim3 blockSize(BLOCKSIZE_x, BLOCKSIZE_y, BLOCKSIZE_z); dim3 blockSize(BLOCKSIZE_x, BLOCKSIZE_y, BLOCKSIZE_z);
make_max_pooling_kernel<<<gridSize, blockSize>>>(input, output, size, output_depth, output_width, stride, int padding); make_max_pooling_kernel<<<gridSize, blockSize>>>(input, output, size, output_depth, output_width, stride, padding);
gpuErrchk( cudaPeekAtLastError() ); gpuErrchk( cudaPeekAtLastError() );
gpuErrchk( cudaDeviceSynchronize() ); gpuErrchk( cudaDeviceSynchronize() );
} }

View File

@ -10,6 +10,9 @@
#include "include/config.h" #include "include/config.h"
#ifdef __CUDACC__
__host__ __device__
#endif
int pooling_not_outside(int x, int y, int lower_bound, int upper_bound) { int pooling_not_outside(int x, int y, int lower_bound, int upper_bound) {
return !(x < lower_bound || y < lower_bound || x >= upper_bound || y>= upper_bound); return !(x < lower_bound || y < lower_bound || x >= upper_bound || y>= upper_bound);
} }
@ -136,7 +139,7 @@ void make_max_pooling_device(float*** input, float*** output, int size, int outp
dim3 gridSize(i_div_up(output_depth, BLOCKSIZE_x), i_div_up(output_width, BLOCKSIZE_y), i_div_up(output_width, BLOCKSIZE_z)); dim3 gridSize(i_div_up(output_depth, BLOCKSIZE_x), i_div_up(output_width, BLOCKSIZE_y), i_div_up(output_width, BLOCKSIZE_z));
dim3 blockSize(BLOCKSIZE_x, BLOCKSIZE_y, BLOCKSIZE_z); dim3 blockSize(BLOCKSIZE_x, BLOCKSIZE_y, BLOCKSIZE_z);
make_max_pooling_kernel<<<gridSize, blockSize>>>(input, output, size, output_depth, output_width, stride, int padding); make_max_pooling_kernel<<<gridSize, blockSize>>>(input, output, size, output_depth, output_width, stride, padding);
gpuErrchk( cudaPeekAtLastError() ); gpuErrchk( cudaPeekAtLastError() );
gpuErrchk( cudaDeviceSynchronize() ); gpuErrchk( cudaDeviceSynchronize() );
} }