feat: Add remove cuda option and cmak config support
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
set(MKL_INTERFACE_FULL intel_lp64)
|
set(MKL_INTERFACE_FULL intel_lp64)
|
||||||
find_package(OpenMP REQUIRED)
|
find_package(OpenMP REQUIRED)
|
||||||
find_package(MKL CONFIG REQUIRED)
|
find_package(MKL CONFIG REQUIRED)
|
||||||
|
if(${USE_CUDA})
|
||||||
enable_language(CUDA)
|
enable_language(CUDA)
|
||||||
find_package(CUDAToolkit REQUIRED)
|
find_package(CUDAToolkit REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(Aurora_MAJOR_VERSION 1)
|
set(Aurora_MAJOR_VERSION 1)
|
||||||
set(Aurora_MINOR_VERSION 0)
|
set(Aurora_MINOR_VERSION 0)
|
||||||
@@ -11,11 +13,17 @@ set(Aurora_BUILD_VERSION 0)
|
|||||||
get_filename_component(Aurora_DIR "${CMAKE_CURRENT_LIST_DIR}/" PATH)
|
get_filename_component(Aurora_DIR "${CMAKE_CURRENT_LIST_DIR}/" PATH)
|
||||||
|
|
||||||
message("Aurora_DIR: ${Aurora_DIR}")
|
message("Aurora_DIR: ${Aurora_DIR}")
|
||||||
file(GLOB_RECURSE Aurora_Source "${Aurora_DIR}/src/[AFSC]*.cpp" "${Aurora_DIR}/src/Matrix*.cpp" "${Aurora_DIR}/src/*.cu")
|
if(${USE_CUDA})
|
||||||
|
file(GLOB_RECURSE Aurora_Source "${Aurora_DIR}/src/*.cpp" "${Aurora_DIR}/src/*.cu")
|
||||||
|
set(Aurora_Libraries $<LINK_ONLY:MKL::MKL> OpenMP::OpenMP_CXX ${CUDA_cublas_LIBRARY} ${CUDA_cusolver_LIBRARY})
|
||||||
|
else()
|
||||||
|
set(Aurora_Libraries $<LINK_ONLY:MKL::MKL> OpenMP::OpenMP_CXX )
|
||||||
|
file(GLOB_RECURSE Aurora_Source "${Aurora_DIR}/src/*.cpp" )
|
||||||
|
endif()
|
||||||
message( ${Aurora_Source})
|
message( ${Aurora_Source})
|
||||||
set(Aurora_INCLUDE_DIRS "${Aurora_DIR}/src" "${Aurora_DIR}/thirdparty/include" $<TARGET_PROPERTY:MKL::MKL,INTERFACE_INCLUDE_DIRECTORIES>)
|
set(Aurora_INCLUDE_DIRS "${Aurora_DIR}/src" "${Aurora_DIR}/thirdparty/include" $<TARGET_PROPERTY:MKL::MKL,INTERFACE_INCLUDE_DIRECTORIES>)
|
||||||
|
|
||||||
set(Aurora_Complie_Options $<TARGET_PROPERTY:MKL::MKL,INTERFACE_COMPILE_OPTIONS> )
|
set(Aurora_Complie_Options $<TARGET_PROPERTY:MKL::MKL,INTERFACE_COMPILE_OPTIONS> )
|
||||||
set(Aurora_Libraries $<LINK_ONLY:MKL::MKL> OpenMP::OpenMP_CXX ${CUDA_cublas_LIBRARY} ${CUDA_cusolver_LIBRARY})
|
|
||||||
set(Aurora_FOUND TRUE)
|
set(Aurora_FOUND TRUE)
|
||||||
message(Aurora Found)
|
message(Aurora Found)
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "CudaMatrix.h"
|
|
||||||
#include "Function3D.h"
|
#include "Function3D.h"
|
||||||
#include "Function2D.h"
|
#include "Function2D.h"
|
||||||
#include "Function.h"
|
#include "Function.h"
|
||||||
#include "CudaMatrixPrivate.cuh"
|
|
||||||
|
#ifdef USE_CUDA
|
||||||
#include <cuda_runtime.h>
|
#include <cuda_runtime.h>
|
||||||
|
#include "CudaMatrixPrivate.cuh"
|
||||||
|
#include "CudaMatrix.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -70,30 +74,11 @@ Matrix Aurora::ones(int aRow, int aColumn, int aSlice) {
|
|||||||
return Matrix::New(data,rowSize,colSize,aSlice);
|
return Matrix::New(data,rowSize,colSize,aSlice);
|
||||||
}
|
}
|
||||||
|
|
||||||
CudaMatrix Aurora::onesCuda(int aRow, int aColumn, int aSlice){
|
|
||||||
if (aRow == 0 || aColumn == 0)
|
|
||||||
{
|
|
||||||
std::cerr<<"ones function can create matrix with dim unit cont =0";
|
|
||||||
return CudaMatrix();
|
|
||||||
}
|
|
||||||
int rowSize = aRow;
|
|
||||||
int colSize = aColumn;
|
|
||||||
int sliceSize = aSlice == 0 ? 1 : aSlice;
|
|
||||||
size_t arraySize = rowSize * colSize* sliceSize;
|
|
||||||
float* data = nullptr;
|
|
||||||
cudaMalloc((void**)&data,arraySize*sizeof(float));
|
|
||||||
::thrustFill(data,data+arraySize,1.0f);
|
|
||||||
return CudaMatrix::fromRawData(data,rowSize,colSize,sliceSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
Matrix Aurora::ones(int aSquareRow) {
|
Matrix Aurora::ones(int aSquareRow) {
|
||||||
return Aurora::ones(aSquareRow, aSquareRow);
|
return Aurora::ones(aSquareRow, aSquareRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
CudaMatrix Aurora::onesCuda(int aSquareRow) {
|
|
||||||
return Aurora::onesCuda(aSquareRow, aSquareRow);
|
|
||||||
}
|
|
||||||
|
|
||||||
Matrix Aurora::zeros(int aRow, int aColumn, int aSlice) {
|
Matrix Aurora::zeros(int aRow, int aColumn, int aSlice) {
|
||||||
if (aRow == 0 || aColumn == 0)
|
if (aRow == 0 || aColumn == 0)
|
||||||
{
|
{
|
||||||
@@ -110,31 +95,11 @@ Matrix Aurora::zeros(int aRow, int aColumn, int aSlice) {
|
|||||||
return Matrix::New(data,rowSize,colSize,sliceSize);
|
return Matrix::New(data,rowSize,colSize,sliceSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
CudaMatrix Aurora::zerosCuda(int aRow, int aColumn, int aSlice) {
|
|
||||||
if (aRow == 0 || aColumn == 0)
|
|
||||||
{
|
|
||||||
std::cerr<<"zeros function can create matrix with dim unit cont =0";
|
|
||||||
return CudaMatrix();
|
|
||||||
}
|
|
||||||
int rowSize = aRow;
|
|
||||||
int colSize = aColumn;
|
|
||||||
int sliceSize = aSlice == 0 ? 1 : aSlice;
|
|
||||||
size_t arraySize = rowSize * colSize* sliceSize;
|
|
||||||
float* data = nullptr;
|
|
||||||
cudaMalloc((void**)&data,arraySize*sizeof(float));
|
|
||||||
::thrustFill(data,data+arraySize,0.0f);
|
|
||||||
return CudaMatrix::fromRawData(data,rowSize,colSize,sliceSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Matrix Aurora::zeros(int aSquareRow) {
|
Matrix Aurora::zeros(int aSquareRow) {
|
||||||
return Aurora::zeros(aSquareRow, aSquareRow);
|
return Aurora::zeros(aSquareRow, aSquareRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
CudaMatrix Aurora::zerosCuda(int aSquareRow) {
|
|
||||||
return Aurora::zerosCuda(aSquareRow, aSquareRow);
|
|
||||||
}
|
|
||||||
|
|
||||||
Matrix Aurora::size(const Matrix &aMatrix)
|
Matrix Aurora::size(const Matrix &aMatrix)
|
||||||
{
|
{
|
||||||
if (aMatrix.isScalar()){
|
if (aMatrix.isScalar()){
|
||||||
@@ -165,50 +130,11 @@ Matrix Aurora::size(const Matrix &aMatrix)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CudaMatrix Aurora::size(const CudaMatrix &aMatrix){
|
|
||||||
float * output=nullptr;
|
|
||||||
if (aMatrix.isScalar()){
|
|
||||||
cudaMalloc((void**)&output,sizeof(float));
|
|
||||||
auto outMatrix = CudaMatrix::fromRawData(output,1,1,1);
|
|
||||||
outMatrix.setValue(0, 1);
|
|
||||||
return outMatrix;
|
|
||||||
}
|
|
||||||
else if (aMatrix.isVector()){
|
|
||||||
cudaMalloc((void**)&output,sizeof(float)*2);
|
|
||||||
auto outMatrix = CudaMatrix::fromRawData(output,2,1,1);
|
|
||||||
outMatrix.setValue(0, aMatrix.getDimSize(0));
|
|
||||||
outMatrix.setValue(1, aMatrix.getDimSize(1));
|
|
||||||
return outMatrix;
|
|
||||||
}
|
|
||||||
//3D
|
|
||||||
else if (aMatrix.getDimSize(2)>1){
|
|
||||||
cudaMalloc((void**)&output,sizeof(float)*3);
|
|
||||||
auto outMatrix = CudaMatrix::fromRawData(output,3,1,1);
|
|
||||||
outMatrix.setValue(0,aMatrix.getDimSize(0));
|
|
||||||
outMatrix.setValue(1,aMatrix.getDimSize(1));
|
|
||||||
outMatrix.setValue(2,aMatrix.getDimSize(2));
|
|
||||||
return outMatrix;
|
|
||||||
}
|
|
||||||
//2D matrix
|
|
||||||
else{
|
|
||||||
cudaMalloc((void**)&output,sizeof(float)*2);
|
|
||||||
auto outMatrix = CudaMatrix::fromRawData(output,2,1,1);
|
|
||||||
outMatrix.setValue(0,aMatrix.getDimSize(0));
|
|
||||||
outMatrix.setValue(1,aMatrix.getDimSize(1));
|
|
||||||
return outMatrix;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int Aurora::size(const Matrix &aMatrix,int dims)
|
int Aurora::size(const Matrix &aMatrix,int dims)
|
||||||
{
|
{
|
||||||
return aMatrix.getDimSize(dims-1);
|
return aMatrix.getDimSize(dims-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Aurora::size(const CudaMatrix &aMatrix,int dims)
|
|
||||||
{
|
|
||||||
return aMatrix.getDimSize(dims-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Matrix Aurora::meshgridInterp3(const Matrix& aX, const Matrix& aY, const Matrix& aZ, const Matrix& aV, const Matrix& aX1, const Matrix& aY1, const Matrix& aZ1,InterpnMethod aMethod, float aExtrapval)
|
Matrix Aurora::meshgridInterp3(const Matrix& aX, const Matrix& aY, const Matrix& aZ, const Matrix& aV, const Matrix& aX1, const Matrix& aY1, const Matrix& aZ1,InterpnMethod aMethod, float aExtrapval)
|
||||||
{
|
{
|
||||||
std::vector<Matrix> zTemps;
|
std::vector<Matrix> zTemps;
|
||||||
@@ -291,3 +217,84 @@ Matrix Aurora::meshgridInterp3(const Matrix& aX, const Matrix& aY, const Matrix&
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_CUDA
|
||||||
|
CudaMatrix Aurora::onesCuda(int aRow, int aColumn, int aSlice){
|
||||||
|
if (aRow == 0 || aColumn == 0)
|
||||||
|
{
|
||||||
|
std::cerr<<"ones function can create matrix with dim unit cont =0";
|
||||||
|
return CudaMatrix();
|
||||||
|
}
|
||||||
|
int rowSize = aRow;
|
||||||
|
int colSize = aColumn;
|
||||||
|
int sliceSize = aSlice == 0 ? 1 : aSlice;
|
||||||
|
size_t arraySize = rowSize * colSize* sliceSize;
|
||||||
|
float* data = nullptr;
|
||||||
|
cudaMalloc((void**)&data,arraySize*sizeof(float));
|
||||||
|
::thrustFill(data,data+arraySize,1.0f);
|
||||||
|
return CudaMatrix::fromRawData(data,rowSize,colSize,sliceSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
CudaMatrix Aurora::onesCuda(int aSquareRow) {
|
||||||
|
return Aurora::onesCuda(aSquareRow, aSquareRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
CudaMatrix Aurora::zerosCuda(int aRow, int aColumn, int aSlice) {
|
||||||
|
if (aRow == 0 || aColumn == 0)
|
||||||
|
{
|
||||||
|
std::cerr<<"zeros function can create matrix with dim unit cont =0";
|
||||||
|
return CudaMatrix();
|
||||||
|
}
|
||||||
|
int rowSize = aRow;
|
||||||
|
int colSize = aColumn;
|
||||||
|
int sliceSize = aSlice == 0 ? 1 : aSlice;
|
||||||
|
size_t arraySize = rowSize * colSize* sliceSize;
|
||||||
|
float* data = nullptr;
|
||||||
|
cudaMalloc((void**)&data,arraySize*sizeof(float));
|
||||||
|
::thrustFill(data,data+arraySize,0.0f);
|
||||||
|
return CudaMatrix::fromRawData(data,rowSize,colSize,sliceSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
CudaMatrix Aurora::zerosCuda(int aSquareRow) {
|
||||||
|
return Aurora::zerosCuda(aSquareRow, aSquareRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
CudaMatrix Aurora::size(const CudaMatrix &aMatrix){
|
||||||
|
float * output=nullptr;
|
||||||
|
if (aMatrix.isScalar()){
|
||||||
|
cudaMalloc((void**)&output,sizeof(float));
|
||||||
|
auto outMatrix = CudaMatrix::fromRawData(output,1,1,1);
|
||||||
|
outMatrix.setValue(0, 1);
|
||||||
|
return outMatrix;
|
||||||
|
}
|
||||||
|
else if (aMatrix.isVector()){
|
||||||
|
cudaMalloc((void**)&output,sizeof(float)*2);
|
||||||
|
auto outMatrix = CudaMatrix::fromRawData(output,2,1,1);
|
||||||
|
outMatrix.setValue(0, aMatrix.getDimSize(0));
|
||||||
|
outMatrix.setValue(1, aMatrix.getDimSize(1));
|
||||||
|
return outMatrix;
|
||||||
|
}
|
||||||
|
//3D
|
||||||
|
else if (aMatrix.getDimSize(2)>1){
|
||||||
|
cudaMalloc((void**)&output,sizeof(float)*3);
|
||||||
|
auto outMatrix = CudaMatrix::fromRawData(output,3,1,1);
|
||||||
|
outMatrix.setValue(0,aMatrix.getDimSize(0));
|
||||||
|
outMatrix.setValue(1,aMatrix.getDimSize(1));
|
||||||
|
outMatrix.setValue(2,aMatrix.getDimSize(2));
|
||||||
|
return outMatrix;
|
||||||
|
}
|
||||||
|
//2D matrix
|
||||||
|
else{
|
||||||
|
cudaMalloc((void**)&output,sizeof(float)*2);
|
||||||
|
auto outMatrix = CudaMatrix::fromRawData(output,2,1,1);
|
||||||
|
outMatrix.setValue(0,aMatrix.getDimSize(0));
|
||||||
|
outMatrix.setValue(1,aMatrix.getDimSize(1));
|
||||||
|
return outMatrix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int Aurora::size(const CudaMatrix &aMatrix,int dims)
|
||||||
|
{
|
||||||
|
return aMatrix.getDimSize(dims-1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "Matrix.h"
|
#include "Matrix.h"
|
||||||
#include "CudaMatrix.h"
|
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <complex>
|
#include <complex>
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "Function1D.h"
|
#include "Function1D.h"
|
||||||
|
|
||||||
#ifdef USE_CUDA
|
#ifdef USE_CUDA
|
||||||
|
#include "CudaMatrix.h"
|
||||||
#include <cuda_runtime.h>
|
#include <cuda_runtime.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user