Add cuda compile define and cmake setting

This commit is contained in:
kradchen
2023-10-30 13:34:51 +08:00
parent e3abe9fabe
commit dd6a22f47d
5 changed files with 25 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
#ifdef USE_CUDA
#include "CudaMatrix.h"
#include "Function.h"
@@ -218,6 +219,7 @@ CudaMatrix CudaMatrix::block(int aDim,int aBeginIndex, int aEndIndex) const
return CudaMatrix::fromRawData(dataOutput,getDimSize(0),dimLength,getDimSize(2),getValueType());
}
case 2:
default:
{
int copySize = dimLength*sliceStride;
cudaMemcpy(dataOutput,
@@ -235,4 +237,6 @@ bool CudaMatrix::setBlockValue(int aDim,int aBeginIndx, int aEndIndex,float valu
std::cerr<<"CudaMatrix block only support 1D-3D data!"<<std::endl;
return false;
}
}
return true;
}
#endif // USE_CUDA

View File

@@ -1,6 +1,6 @@
#ifndef CUDAMATRIX_H
#define CUDAMATRIX_H
#ifdef USE_CUDA
#include "Matrix.h"
@@ -235,5 +235,5 @@ namespace Aurora
std::vector<int> mInfo;
};
}
#endif // USE_CUDA
#endif

View File

@@ -13,7 +13,10 @@
#include <Eigen/Core>
#include <Eigen/Eigen>
#include <Eigen/Dense>
#ifdef USE_CUDA
#include <cuda_runtime.h>
#endif
namespace Aurora {
@@ -26,9 +29,10 @@ namespace Aurora {
void free(void* ptr){
mkl_free(ptr);
}
#ifdef USE_CUDA
void gpuFree(void* ptr)
{
cudaFree(ptr);
}
#endif
}

View File

@@ -17,7 +17,9 @@
#include "Eigen/src/Core/Matrix.h"
#include "Function.h"
#ifdef USE_CUDA
#include <cuda_runtime.h>
#endif
namespace Aurora{
typedef void(*CalcFuncD)(const MKL_INT n, const float a[], const MKL_INT inca, const float b[],
@@ -394,6 +396,7 @@ namespace Aurora {
return ret;
}
#ifdef USE_CUDA
CudaMatrix Matrix::toDeviceMatrix() const
{
float* deviceData = nullptr;
@@ -401,7 +404,7 @@ namespace Aurora {
cudaMemcpy(deviceData, mData.get(), sizeof(float) * getDataSize() * getValueType(), cudaMemcpyHostToDevice);
return CudaMatrix::fromRawData(deviceData, mInfo[0], mInfo[1], mInfo[2], getValueType());
}
#endif
Matrix Matrix::New(float *data, const Matrix &shapeMatrix) {
return New(data,
shapeMatrix.getDimSize(0),