mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-06 01:34:22 +00:00
Initialize and use cuBLAS properly
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace Layers {
|
||||
virtual ~ILayer() {}
|
||||
|
||||
virtual void forward(const float* input, float* output) = 0;
|
||||
virtual void to_cuda() = 0;
|
||||
};
|
||||
|
||||
} // namespace Layers
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user