Initialize and use cuBLAS properly

This commit is contained in:
2024-02-10 17:17:07 +01:00
parent 3e6b7dc7e6
commit 22e33a395b
5 changed files with 35 additions and 12 deletions

View File

@@ -15,7 +15,8 @@ namespace Layers {
~Dense();
void forward(const float* input, float* output);
void to_cuda();
virtual void setWeights(const std::vector<std::vector<float>>& weights) = 0;
virtual void setBiases(const std::vector<float>& biases) = 0;
private:
int inputSize;
@@ -31,6 +32,7 @@ namespace Layers {
void initializeWeights();
void initializeBiases();
void toCuda();
};
} // namespace Layers

View File

@@ -11,7 +11,6 @@ namespace Layers {
virtual ~ILayer() {}
virtual void forward(const float* input, float* output) = 0;
virtual void to_cuda() = 0;
};
} // namespace Layers

View File

@@ -2,6 +2,7 @@
#define CUDA_HELPER_H
#include <cuda_runtime.h>
#include <cublas_v2.h>
#define IDX2C(i,j,ld) (((j)*(ld))+(i))
@@ -17,7 +18,15 @@ do { \
} \
} while (0)
// Initialize CUDA and return the device properties
cudaDeviceProp initializeCUDA();
// cuBLAS error checking macro
#define CUBLAS_CHECK(call) \
do { \
cublasStatus_t result = call; \
if (result != CUBLAS_STATUS_SUCCESS) { \
fprintf(stderr, "cuBLAS error at %s:%d code=%d\n", \
__FILE__, __LINE__, static_cast<int>(result)); \
exit(EXIT_FAILURE); \
} \
} while (0)
#endif // CUDA_HELPER_H