|
|
|
|
@@ -1,10 +1,14 @@
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include "CudaMatrix.h"
|
|
|
|
|
|
|
|
|
|
#include "Function3D.h"
|
|
|
|
|
#include "Function2D.h"
|
|
|
|
|
#include "Function.h"
|
|
|
|
|
#include "CudaMatrixPrivate.cuh"
|
|
|
|
|
|
|
|
|
|
#ifdef USE_CUDA
|
|
|
|
|
#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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
return Aurora::ones(aSquareRow, aSquareRow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CudaMatrix Aurora::onesCuda(int aSquareRow) {
|
|
|
|
|
return Aurora::onesCuda(aSquareRow, aSquareRow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Matrix Aurora::zeros(int aRow, int aColumn, int aSlice) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
return Aurora::zeros(aSquareRow, aSquareRow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CudaMatrix Aurora::zerosCuda(int aSquareRow) {
|
|
|
|
|
return Aurora::zerosCuda(aSquareRow, aSquareRow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Matrix Aurora::size(const Matrix &aMatrix)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
std::vector<Matrix> zTemps;
|
|
|
|
|
@@ -291,3 +217,84 @@ Matrix Aurora::meshgridInterp3(const Matrix& aX, const Matrix& aY, const Matrix&
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|