Cuda matrix compare and value getter and setter
This commit is contained in:
@@ -912,5 +912,171 @@ bool CudaMatrix::setBlock(int aDim,int aBeginIndex, int aEndIndex, const CudaMat
|
||||
unaryNeg(aMatrix.getData(),out.getData(),aMatrix.getDataSize());
|
||||
return out;
|
||||
}
|
||||
|
||||
//----compare---------------------------------------------------
|
||||
CudaMatrix CudaMatrix::operator>(float aScalar) const{
|
||||
float* data = nullptr;
|
||||
unsigned long long size = this->getDataSize() * this->getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, this->getDimSize(0), this->getDimSize(1), this->getDimSize(2), this->getValueType());
|
||||
unaryCompare(this->getData(),aScalar,data,this->getDataSize(),::G);
|
||||
return out;
|
||||
}
|
||||
CudaMatrix operator>(float aScalar, const CudaMatrix &aMatrix){
|
||||
float* data = nullptr;
|
||||
unsigned long long size = aMatrix.getDataSize() * aMatrix.getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, aMatrix.getDimSize(0), aMatrix.getDimSize(1), aMatrix.getDimSize(2), aMatrix.getValueType());
|
||||
unaryCompare(aScalar,aMatrix.getData(),data,aMatrix.getDataSize(),::G);
|
||||
return out;
|
||||
}
|
||||
CudaMatrix CudaMatrix::operator>(const CudaMatrix &aMatrix) const{
|
||||
float* data = nullptr;
|
||||
unsigned long long size = aMatrix.getDataSize() * aMatrix.getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, aMatrix.getDimSize(0), aMatrix.getDimSize(1), aMatrix.getDimSize(2), aMatrix.getValueType());
|
||||
unaryCompare(this->getData(),aMatrix.getData(),data,this->getDataSize(),::G);
|
||||
return out;
|
||||
}
|
||||
|
||||
CudaMatrix CudaMatrix::operator<(float aScalar) const{
|
||||
float* data = nullptr;
|
||||
unsigned long long size = this->getDataSize() * this->getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, this->getDimSize(0), this->getDimSize(1), this->getDimSize(2), this->getValueType());
|
||||
unaryCompare(this->getData(),aScalar,data,this->getDataSize(),::L);
|
||||
return out;
|
||||
}
|
||||
CudaMatrix operator<(float aScalar, const CudaMatrix &aMatrix){
|
||||
float* data = nullptr;
|
||||
unsigned long long size = aMatrix.getDataSize() * aMatrix.getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, aMatrix.getDimSize(0), aMatrix.getDimSize(1), aMatrix.getDimSize(2), aMatrix.getValueType());
|
||||
unaryCompare(aScalar,aMatrix.getData(),data,aMatrix.getDataSize(),::L);
|
||||
return out;
|
||||
}
|
||||
CudaMatrix CudaMatrix::operator<(const CudaMatrix &aMatrix) const{
|
||||
float* data = nullptr;
|
||||
unsigned long long size = aMatrix.getDataSize() * aMatrix.getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, aMatrix.getDimSize(0), aMatrix.getDimSize(1), aMatrix.getDimSize(2), aMatrix.getValueType());
|
||||
unaryCompare(this->getData(),aMatrix.getData(),data,this->getDataSize(),::L);
|
||||
return out;
|
||||
}
|
||||
|
||||
CudaMatrix CudaMatrix::operator>=(float aScalar) const{
|
||||
float* data = nullptr;
|
||||
unsigned long long size = this->getDataSize() * this->getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, this->getDimSize(0), this->getDimSize(1), this->getDimSize(2), this->getValueType());
|
||||
unaryCompare(this->getData(),aScalar,data,this->getDataSize(),::GE);
|
||||
return out;
|
||||
}
|
||||
|
||||
CudaMatrix operator>=(float aScalar, const CudaMatrix &aMatrix){
|
||||
float* data = nullptr;
|
||||
unsigned long long size = aMatrix.getDataSize() * aMatrix.getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, aMatrix.getDimSize(0), aMatrix.getDimSize(1), aMatrix.getDimSize(2), aMatrix.getValueType());
|
||||
unaryCompare(aScalar,aMatrix.getData(),data,aMatrix.getDataSize(),::GE);
|
||||
return out;
|
||||
}
|
||||
|
||||
CudaMatrix CudaMatrix::operator>=(const CudaMatrix &aMatrix) const{
|
||||
float* data = nullptr;
|
||||
unsigned long long size = aMatrix.getDataSize() * aMatrix.getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, aMatrix.getDimSize(0), aMatrix.getDimSize(1), aMatrix.getDimSize(2), aMatrix.getValueType());
|
||||
unaryCompare(this->getData(),aMatrix.getData(),data,this->getDataSize(),::GE);
|
||||
return out;
|
||||
}
|
||||
CudaMatrix CudaMatrix::operator<=(float aScalar) const{
|
||||
float* data = nullptr;
|
||||
unsigned long long size = this->getDataSize() * this->getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, this->getDimSize(0), this->getDimSize(1), this->getDimSize(2), this->getValueType());
|
||||
unaryCompare(this->getData(),aScalar,data,this->getDataSize(),::LE);
|
||||
return out;
|
||||
}
|
||||
CudaMatrix operator<=(float aScalar, const CudaMatrix &aMatrix){
|
||||
float* data = nullptr;
|
||||
unsigned long long size = aMatrix.getDataSize() * aMatrix.getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, aMatrix.getDimSize(0), aMatrix.getDimSize(1), aMatrix.getDimSize(2), aMatrix.getValueType());
|
||||
unaryCompare(aScalar,aMatrix.getData(),data,aMatrix.getDataSize(),::LE);
|
||||
return out;
|
||||
}
|
||||
CudaMatrix CudaMatrix::operator<=(const CudaMatrix &aMatrix) const{
|
||||
float* data = nullptr;
|
||||
unsigned long long size = aMatrix.getDataSize() * aMatrix.getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, aMatrix.getDimSize(0), aMatrix.getDimSize(1), aMatrix.getDimSize(2), aMatrix.getValueType());
|
||||
unaryCompare(this->getData(),aMatrix.getData(),data,this->getDataSize(),::LE);
|
||||
return out;
|
||||
}
|
||||
CudaMatrix CudaMatrix::operator==(float aScalar) const{
|
||||
float* data = nullptr;
|
||||
unsigned long long size = this->getDataSize() * this->getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, this->getDimSize(0), this->getDimSize(1), this->getDimSize(2), this->getValueType());
|
||||
unaryCompare(this->getData(),aScalar,data,this->getDataSize(),::E);
|
||||
return out;
|
||||
}
|
||||
CudaMatrix operator==(float aScalar, const CudaMatrix &aMatrix){
|
||||
float* data = nullptr;
|
||||
unsigned long long size = aMatrix.getDataSize() * aMatrix.getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, aMatrix.getDimSize(0), aMatrix.getDimSize(1), aMatrix.getDimSize(2), aMatrix.getValueType());
|
||||
unaryCompare(aScalar,aMatrix.getData(),data,aMatrix.getDataSize(),::E);
|
||||
return out;
|
||||
}
|
||||
CudaMatrix CudaMatrix::operator==(const CudaMatrix &aMatrix) const{
|
||||
float* data = nullptr;
|
||||
unsigned long long size = aMatrix.getDataSize() * aMatrix.getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, aMatrix.getDimSize(0), aMatrix.getDimSize(1), aMatrix.getDimSize(2), aMatrix.getValueType());
|
||||
unaryCompare(this->getData(),aMatrix.getData(),data,this->getDataSize(),::E);
|
||||
return out;
|
||||
}
|
||||
CudaMatrix CudaMatrix::operator!=(float aScalar) const{
|
||||
float* data = nullptr;
|
||||
unsigned long long size = this->getDataSize() * this->getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, this->getDimSize(0), this->getDimSize(1), this->getDimSize(2), this->getValueType());
|
||||
unaryCompare(this->getData(),aScalar,data,this->getDataSize(),::NE);
|
||||
return out;
|
||||
}
|
||||
CudaMatrix operator!=(float aScalar, const CudaMatrix &aMatrix){
|
||||
float* data = nullptr;
|
||||
unsigned long long size = aMatrix.getDataSize() * aMatrix.getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, aMatrix.getDimSize(0), aMatrix.getDimSize(1), aMatrix.getDimSize(2), aMatrix.getValueType());
|
||||
unaryCompare(aScalar,aMatrix.getData(),data,aMatrix.getDataSize(),::NE);
|
||||
return out;
|
||||
}
|
||||
CudaMatrix CudaMatrix::operator!=(const CudaMatrix &aMatrix) const{
|
||||
float* data = nullptr;
|
||||
unsigned long long size = aMatrix.getDataSize() * aMatrix.getValueType();
|
||||
cudaMalloc((void**)&data, sizeof(float) * size);
|
||||
auto out = CudaMatrix::fromRawData(data, aMatrix.getDimSize(0), aMatrix.getDimSize(1), aMatrix.getDimSize(2), aMatrix.getValueType());
|
||||
unaryCompare(this->getData(),aMatrix.getData(),data,this->getDataSize(),::NE);
|
||||
return out;
|
||||
}
|
||||
float CudaMatrix::getValue(size_t index){
|
||||
float result;
|
||||
cudaError_t cuda_error = cudaMemcpy(&result, getData() + index, sizeof(float), cudaMemcpyDeviceToHost);
|
||||
|
||||
if (cuda_error != cudaSuccess) {
|
||||
fprintf(stderr, "CUDA error: %s\n", cudaGetErrorString(cuda_error));
|
||||
return nan("");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
void CudaMatrix::setValue(size_t index, const float& value){
|
||||
cudaError_t cuda_error = cudaMemcpy( getData() + index,&value, sizeof(float), cudaMemcpyHostToDevice);
|
||||
if (cuda_error != cudaSuccess) {
|
||||
fprintf(stderr, "CUDA error: %s\n", cudaGetErrorString(cuda_error));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // USE_CUDA
|
||||
|
||||
Reference in New Issue
Block a user