mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
refactor cuistl namespace
This commit is contained in:
@@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE(TestFiniteDifference1D)
|
||||
expectedOutputVector[i][1] = 43.0;
|
||||
inputVector[i][0] = 1.0;
|
||||
auto converter
|
||||
= Opm::cuistl::PreconditionerConvertFieldTypeAdapter<TestPreconditioner, SpMatrixDouble, XDouble, XDouble>(
|
||||
= Opm::gpuistl::PreconditionerConvertFieldTypeAdapter<TestPreconditioner, SpMatrixDouble, XDouble, XDouble>(
|
||||
B);
|
||||
auto underlyingPreconditioner = std::make_shared<TestPreconditioner>(
|
||||
converter.getConvertedMatrix(), inputVector, B, expectedOutputVector);
|
||||
|
||||
@@ -85,10 +85,10 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(FlattenAndInvertDiagonalWith3By3Blocks, T, Numeric
|
||||
B[1][1][1][1] = -1.0;
|
||||
B[1][1][2][2] = -1.0;
|
||||
|
||||
Opm::cuistl::CuSparseMatrix<T> m = Opm::cuistl::CuSparseMatrix<T>::fromMatrix(B);
|
||||
Opm::cuistl::CuVector<T> dInvDiag(blocksize * blocksize * N);
|
||||
Opm::gpuistl::CuSparseMatrix<T> m = Opm::gpuistl::CuSparseMatrix<T>::fromMatrix(B);
|
||||
Opm::gpuistl::CuVector<T> dInvDiag(blocksize * blocksize * N);
|
||||
|
||||
Opm::cuistl::detail::JAC::invertDiagonalAndFlatten<T, 3>(
|
||||
Opm::gpuistl::detail::JAC::invertDiagonalAndFlatten<T, 3>(
|
||||
m.getNonZeroValues().data(), m.getRowIndices().data(), m.getColumnIndices().data(), N, dInvDiag.data());
|
||||
|
||||
std::vector<T> expectedInvDiag {-1.0 / 4.0,
|
||||
@@ -159,10 +159,10 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(FlattenAndInvertDiagonalWith2By2Blocks, T, Numeric
|
||||
B[1][1][0][0] = -1.0;
|
||||
B[1][1][1][1] = -1.0;
|
||||
|
||||
Opm::cuistl::CuSparseMatrix<T> m = Opm::cuistl::CuSparseMatrix<T>::fromMatrix(B);
|
||||
Opm::cuistl::CuVector<T> dInvDiag(blocksize * blocksize * N);
|
||||
Opm::gpuistl::CuSparseMatrix<T> m = Opm::gpuistl::CuSparseMatrix<T>::fromMatrix(B);
|
||||
Opm::gpuistl::CuVector<T> dInvDiag(blocksize * blocksize * N);
|
||||
|
||||
Opm::cuistl::detail::JAC::invertDiagonalAndFlatten<T, 2>(
|
||||
Opm::gpuistl::detail::JAC::invertDiagonalAndFlatten<T, 2>(
|
||||
m.getNonZeroValues().data(), m.getRowIndices().data(), m.getColumnIndices().data(), N, dInvDiag.data());
|
||||
|
||||
std::vector<T> expectedInvDiag {2.0, -2.0, -1.0 / 2.0, 1.0, -1.0, 0.0, 0.0, -1.0};
|
||||
|
||||
@@ -47,11 +47,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ElementWiseMultiplicationOf3By3BlockVectorAndVecto
|
||||
std::vector<T> hostBlockVector({1.0, 2.0, 3.0, 5.0, 2.0, 3.0, 2.0, 1.0, 2.0});
|
||||
std::vector<T> hostVecVector({3.0, 2.0, 1.0});
|
||||
std::vector<T> hostDstVector({0, 0, 0});
|
||||
Opm::cuistl::CuVector<T> deviceBlockVector(hostBlockVector);
|
||||
Opm::cuistl::CuVector<T> deviceVecVector(hostVecVector);
|
||||
Opm::cuistl::CuVector<T> deviceDstVector(hostDstVector);
|
||||
Opm::gpuistl::CuVector<T> deviceBlockVector(hostBlockVector);
|
||||
Opm::gpuistl::CuVector<T> deviceVecVector(hostVecVector);
|
||||
Opm::gpuistl::CuVector<T> deviceDstVector(hostDstVector);
|
||||
|
||||
Opm::cuistl::detail::weightedDiagMV(
|
||||
Opm::gpuistl::detail::weightedDiagMV(
|
||||
deviceBlockVector.data(), N, blocksize, weight, deviceVecVector.data(), deviceDstVector.data());
|
||||
|
||||
std::vector<T> expectedVec {10.0, 22.0, 10.0};
|
||||
@@ -81,11 +81,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ElementWiseMultiplicationOf2By2BlockVectorAndVecto
|
||||
std::vector<T> hostBlockVector({1.0, 2.0, 3.0, 4.0, 4.0, 3.0, 2.0, 1.0});
|
||||
std::vector<T> hostVecVector({1.0, 3.0, 2.0, 4.0});
|
||||
std::vector<T> hostDstVector({0, 0, 0, 0});
|
||||
Opm::cuistl::CuVector<T> deviceBlockVector(hostBlockVector);
|
||||
Opm::cuistl::CuVector<T> deviceVecVector(hostVecVector);
|
||||
Opm::cuistl::CuVector<T> deviceDstVector(hostDstVector);
|
||||
Opm::gpuistl::CuVector<T> deviceBlockVector(hostBlockVector);
|
||||
Opm::gpuistl::CuVector<T> deviceVecVector(hostVecVector);
|
||||
Opm::gpuistl::CuVector<T> deviceDstVector(hostDstVector);
|
||||
|
||||
Opm::cuistl::detail::weightedDiagMV(
|
||||
Opm::gpuistl::detail::weightedDiagMV(
|
||||
deviceBlockVector.data(), N, blocksize, weight, deviceVecVector.data(), deviceDstVector.data());
|
||||
|
||||
std::vector<T> expectedVec {3.5, 7.5, 10.0, 4.0};
|
||||
@@ -95,4 +95,4 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ElementWiseMultiplicationOf2By2BlockVectorAndVecto
|
||||
for (size_t i = 0; i < expectedVec.size(); i++) {
|
||||
BOOST_CHECK_CLOSE(expectedVec[i], computedVec[i], 1e-7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE(TestGetCublasVersion)
|
||||
// that checks the version of blas programatically. Let the test pass for now.
|
||||
BOOST_CHECK(true);
|
||||
#else
|
||||
auto& cublasHandle = ::Opm::cuistl::detail::CuBlasHandle::getInstance();
|
||||
auto& cublasHandle = ::Opm::gpuistl::detail::CuBlasHandle::getInstance();
|
||||
int cuBlasVersion = -1;
|
||||
OPM_CUBLAS_SAFE_CALL(cublasGetVersion(cublasHandle.get(), &cuBlasVersion));
|
||||
|
||||
|
||||
@@ -35,15 +35,15 @@ BOOST_AUTO_TEST_CASE(TestMakeView)
|
||||
{
|
||||
// test that we can create buffers and make views of the buffers using the pointer constructor
|
||||
auto buf = std::vector<int>({1, 2, 3, 4, 5, 6});
|
||||
const auto gpubuf = ::Opm::cuistl::CuBuffer<int>(buf);
|
||||
auto gpuview = ::Opm::cuistl::CuView<int>(buf.data(), buf.size());
|
||||
bool gpuBufCreatedView = std::is_same<::Opm::cuistl::CuView<int>, decltype(gpuview)>::value;
|
||||
const auto gpubuf = ::Opm::gpuistl::CuBuffer<int>(buf);
|
||||
auto gpuview = ::Opm::gpuistl::CuView<int>(buf.data(), buf.size());
|
||||
bool gpuBufCreatedView = std::is_same<::Opm::gpuistl::CuView<int>, decltype(gpuview)>::value;
|
||||
|
||||
BOOST_CHECK(gpuBufCreatedView);
|
||||
|
||||
// test that we can make views of buffers by using the cubuffer constructor
|
||||
auto gpuview2 = ::Opm::cuistl::make_view(gpubuf);
|
||||
bool gpuBufCreatedView2 = std::is_same<::Opm::cuistl::CuView<const int>, decltype(gpuview2)>::value;
|
||||
auto gpuview2 = ::Opm::gpuistl::make_view(gpubuf);
|
||||
bool gpuBufCreatedView2 = std::is_same<::Opm::gpuistl::CuView<const int>, decltype(gpuview2)>::value;
|
||||
|
||||
BOOST_CHECK(gpuBufCreatedView2);
|
||||
|
||||
|
||||
@@ -41,11 +41,11 @@ using B1x1Vec = Dune::BlockVector<Dune::FieldVector<double, 1>>;
|
||||
using B2x2Vec = Dune::BlockVector<Dune::FieldVector<double, 2>>;
|
||||
using Sp1x1BlockMatrix = Dune::BCRSMatrix<FM1x1>;
|
||||
using Sp2x2BlockMatrix = Dune::BCRSMatrix<FM2x2>;
|
||||
using CuMatrix = Opm::cuistl::CuSparseMatrix<T>;
|
||||
using CuIntVec = Opm::cuistl::CuVector<int>;
|
||||
using CuFloatingPointVec = Opm::cuistl::CuVector<T>;
|
||||
using CuDilu1x1 = Opm::cuistl::CuDILU<Sp1x1BlockMatrix, CuFloatingPointVec, CuFloatingPointVec>;
|
||||
using CuDilu2x2 = Opm::cuistl::CuDILU<Sp2x2BlockMatrix, CuFloatingPointVec, CuFloatingPointVec>;
|
||||
using CuMatrix = Opm::gpuistl::CuSparseMatrix<T>;
|
||||
using CuIntVec = Opm::gpuistl::CuVector<int>;
|
||||
using CuFloatingPointVec = Opm::gpuistl::CuVector<T>;
|
||||
using CuDilu1x1 = Opm::gpuistl::CuDILU<Sp1x1BlockMatrix, CuFloatingPointVec, CuFloatingPointVec>;
|
||||
using CuDilu2x2 = Opm::gpuistl::CuDILU<Sp2x2BlockMatrix, CuFloatingPointVec, CuFloatingPointVec>;
|
||||
|
||||
Sp1x1BlockMatrix
|
||||
get1x1BlockTestMatrix()
|
||||
|
||||
@@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(CUJACApplyBlocksize2, T, NumericTypes)
|
||||
using M = Dune::FieldMatrix<T, blocksize, blocksize>;
|
||||
using SpMatrix = Dune::BCRSMatrix<M>;
|
||||
using Vector = Dune::BlockVector<Dune::FieldVector<T, blocksize>>;
|
||||
using CuJac = Opm::cuistl::CuJac<SpMatrix, Opm::cuistl::CuVector<T>, Opm::cuistl::CuVector<T>>;
|
||||
using CuJac = Opm::gpuistl::CuJac<SpMatrix, Opm::gpuistl::CuVector<T>, Opm::gpuistl::CuVector<T>>;
|
||||
|
||||
SpMatrix B(N, N, nonZeroes, SpMatrix::row_wise);
|
||||
for (auto row = B.createbegin(); row != B.createend(); ++row) {
|
||||
@@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(CUJACApplyBlocksize2, T, NumericTypes)
|
||||
B[1][1][0][0] = -1.0;
|
||||
B[1][1][1][1] = -1.0;
|
||||
|
||||
auto cujac = Opm::cuistl::PreconditionerAdapter<Vector, Vector, CuJac>(std::make_shared<CuJac>(B, 0.5));
|
||||
auto cujac = Opm::gpuistl::PreconditionerAdapter<Vector, Vector, CuJac>(std::make_shared<CuJac>(B, 0.5));
|
||||
|
||||
Vector vVector(2);
|
||||
Vector dVector(2);
|
||||
@@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(CUJACApplyBlocksize1, T, NumericTypes)
|
||||
using M = Dune::FieldMatrix<T, blocksize, blocksize>;
|
||||
using SpMatrix = Dune::BCRSMatrix<M>;
|
||||
using Vector = Dune::BlockVector<Dune::FieldVector<T, blocksize>>;
|
||||
using CuJac = Opm::cuistl::CuJac<SpMatrix, Opm::cuistl::CuVector<T>, Opm::cuistl::CuVector<T>>;
|
||||
using CuJac = Opm::gpuistl::CuJac<SpMatrix, Opm::gpuistl::CuVector<T>, Opm::gpuistl::CuVector<T>>;
|
||||
|
||||
SpMatrix B(N, N, nonZeroes, SpMatrix::row_wise);
|
||||
for (auto row = B.createbegin(); row != B.createend(); ++row) {
|
||||
@@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(CUJACApplyBlocksize1, T, NumericTypes)
|
||||
B[2][2][0][0] = -1.0;
|
||||
B[3][3][0][0] = -1.0;
|
||||
|
||||
auto cujac = Opm::cuistl::PreconditionerAdapter<Vector, Vector, CuJac>(std::make_shared<CuJac>(B, 0.5));
|
||||
auto cujac = Opm::gpuistl::PreconditionerAdapter<Vector, Vector, CuJac>(std::make_shared<CuJac>(B, 0.5));
|
||||
|
||||
Vector vVector(4);
|
||||
Vector dVector(4);
|
||||
|
||||
@@ -46,7 +46,7 @@ main(int argc, char** argv)
|
||||
int rank, totalRanks;
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
||||
MPI_Comm_size(MPI_COMM_WORLD, &totalRanks);
|
||||
Opm::cuistl::setDevice(rank, totalRanks);
|
||||
Opm::gpuistl::setDevice(rank, totalRanks);
|
||||
boost::unit_test::unit_test_main(&init_unit_test_func, argc, argv);
|
||||
}
|
||||
|
||||
@@ -62,12 +62,12 @@ BOOST_AUTO_TEST_CASE(TestProject)
|
||||
|
||||
auto ownerOverlapCopy = Dune::OwnerOverlapCopyCommunication<int>(indexInfo, MPI_COMM_WORLD);
|
||||
auto xCPU = std::vector<double> {{1.0, 2.0, 3.0}};
|
||||
auto xGPU = Opm::cuistl::CuVector<double>(xCPU);
|
||||
auto xGPU = Opm::gpuistl::CuVector<double>(xCPU);
|
||||
|
||||
auto gpuComm = std::make_shared<Opm::cuistl::GPUObliviousMPISender<double, 1, Dune::OwnerOverlapCopyCommunication<int>>>(ownerOverlapCopy);
|
||||
auto gpuComm = std::make_shared<Opm::gpuistl::GPUObliviousMPISender<double, 1, Dune::OwnerOverlapCopyCommunication<int>>>(ownerOverlapCopy);
|
||||
|
||||
auto cuOwnerOverlapCopy
|
||||
= Opm::cuistl::CuOwnerOverlapCopy<double, 1, Dune::OwnerOverlapCopyCommunication<int>>(gpuComm);
|
||||
= Opm::gpuistl::CuOwnerOverlapCopy<double, 1, Dune::OwnerOverlapCopyCommunication<int>>(gpuComm);
|
||||
|
||||
cuOwnerOverlapCopy.project(xGPU);
|
||||
|
||||
@@ -94,12 +94,12 @@ BOOST_AUTO_TEST_CASE(TestDot)
|
||||
indexInfo.addRemoteIndex(std::make_tuple(0, 2, Dune::OwnerOverlapCopyAttributeSet::copy));
|
||||
auto ownerOverlapCopy = Dune::OwnerOverlapCopyCommunication<int>(indexInfo, MPI_COMM_WORLD);
|
||||
auto xCPU = std::vector<double> {{1.0, 2.0, 3.0}};
|
||||
auto xGPU = Opm::cuistl::CuVector<double>(xCPU);
|
||||
auto xGPU = Opm::gpuistl::CuVector<double>(xCPU);
|
||||
|
||||
auto gpuComm = std::make_shared<Opm::cuistl::GPUObliviousMPISender<double, 1, Dune::OwnerOverlapCopyCommunication<int>>>(ownerOverlapCopy);
|
||||
auto gpuComm = std::make_shared<Opm::gpuistl::GPUObliviousMPISender<double, 1, Dune::OwnerOverlapCopyCommunication<int>>>(ownerOverlapCopy);
|
||||
|
||||
auto cuOwnerOverlapCopy
|
||||
= Opm::cuistl::CuOwnerOverlapCopy<double, 1, Dune::OwnerOverlapCopyCommunication<int>>(gpuComm);
|
||||
= Opm::gpuistl::CuOwnerOverlapCopy<double, 1, Dune::OwnerOverlapCopyCommunication<int>>(gpuComm);
|
||||
|
||||
double outputDune = -1.0;
|
||||
auto xDune = xGPU.asDuneBlockVector<1>();
|
||||
|
||||
@@ -63,7 +63,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(TestFiniteDifference1D, T, NumericTypes)
|
||||
using M = Dune::FieldMatrix<T, 1, 1>;
|
||||
using SpMatrix = Dune::BCRSMatrix<M>;
|
||||
using Vector = Dune::BlockVector<Dune::FieldVector<T, 1>>;
|
||||
using CuILU0 = Opm::cuistl::CuSeqILU0<SpMatrix, Opm::cuistl::CuVector<T>, Opm::cuistl::CuVector<T>>;
|
||||
using CuILU0 = Opm::gpuistl::CuSeqILU0<SpMatrix, Opm::gpuistl::CuVector<T>, Opm::gpuistl::CuVector<T>>;
|
||||
|
||||
SpMatrix B(N, N, nonZeroes, SpMatrix::row_wise);
|
||||
for (auto row = B.createbegin(); row != B.createend(); ++row) {
|
||||
@@ -91,7 +91,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(TestFiniteDifference1D, T, NumericTypes)
|
||||
|
||||
auto duneILU = Dune::SeqILU<SpMatrix, Vector, Vector>(B, 1.0);
|
||||
|
||||
auto cuILU = Opm::cuistl::PreconditionerAdapter<Vector, Vector, CuILU0>(std::make_shared<CuILU0>(B, 1.0));
|
||||
auto cuILU = Opm::gpuistl::PreconditionerAdapter<Vector, Vector, CuILU0>(std::make_shared<CuILU0>(B, 1.0));
|
||||
|
||||
// check for the standard basis {e_i}
|
||||
// (e_i=(0,...,0, 1 (i-th place), 0, ..., 0))
|
||||
@@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(TestFiniteDifferenceBlock2, T, NumericTypes)
|
||||
using M = Dune::FieldMatrix<T, 2, 2>;
|
||||
using SpMatrix = Dune::BCRSMatrix<M>;
|
||||
using Vector = Dune::BlockVector<Dune::FieldVector<T, 2>>;
|
||||
using CuILU0 = Opm::cuistl::CuSeqILU0<SpMatrix, Opm::cuistl::CuVector<T>, Opm::cuistl::CuVector<T>>;
|
||||
using CuILU0 = Opm::gpuistl::CuSeqILU0<SpMatrix, Opm::gpuistl::CuVector<T>, Opm::gpuistl::CuVector<T>>;
|
||||
|
||||
SpMatrix B(N, N, nonZeroes, SpMatrix::row_wise);
|
||||
for (auto row = B.createbegin(); row != B.createend(); ++row) {
|
||||
@@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(TestFiniteDifferenceBlock2, T, NumericTypes)
|
||||
|
||||
auto duneILU = Dune::SeqILU<SpMatrix, Vector, Vector>(B, 1.0);
|
||||
|
||||
auto cuILU = Opm::cuistl::PreconditionerAdapter<Vector, Vector, CuILU0>(std::make_shared<CuILU0>(B, 1.0));
|
||||
auto cuILU = Opm::gpuistl::PreconditionerAdapter<Vector, Vector, CuILU0>(std::make_shared<CuILU0>(B, 1.0));
|
||||
|
||||
// check for the standard basis {e_i}
|
||||
// (e_i=(0,...,0, 1 (i-th place), 0, ..., 0))
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestGetSparseVersion)
|
||||
{
|
||||
auto& cuSparseHandle = ::Opm::cuistl::detail::CuSparseHandle::getInstance();
|
||||
auto& cuSparseHandle = ::Opm::gpuistl::detail::CuSparseHandle::getInstance();
|
||||
int cuSparseVersion = -1;
|
||||
OPM_CUSPARSE_SAFE_CALL(cusparseGetVersion(cuSparseHandle.get(), &cuSparseVersion));
|
||||
BOOST_CHECK_LT(0, cuSparseVersion);
|
||||
|
||||
@@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(TestConstruction1D)
|
||||
}
|
||||
}
|
||||
|
||||
auto cuSparseMatrix = Opm::cuistl::CuSparseMatrix<double>::fromMatrix(B);
|
||||
auto cuSparseMatrix = Opm::gpuistl::CuSparseMatrix<double>::fromMatrix(B);
|
||||
|
||||
const auto& nonZeroValuesCuda = cuSparseMatrix.getNonZeroValues();
|
||||
std::vector<double> buffer(cuSparseMatrix.nonzeroes(), 0.0);
|
||||
@@ -143,14 +143,14 @@ BOOST_AUTO_TEST_CASE(RandomSparsityMatrix)
|
||||
}
|
||||
}
|
||||
|
||||
auto cuSparseMatrix = Opm::cuistl::CuSparseMatrix<double>::fromMatrix(B);
|
||||
auto cuSparseMatrix = Opm::gpuistl::CuSparseMatrix<double>::fromMatrix(B);
|
||||
// check each column
|
||||
for (size_t component = 0; component < N; ++component) {
|
||||
std::vector<double> inputDataX(N * dim, 0.0);
|
||||
inputDataX[component] = 1.0;
|
||||
std::vector<double> inputDataY(N * dim, .25);
|
||||
auto inputVectorX = Opm::cuistl::CuVector<double>(inputDataX.data(), inputDataX.size());
|
||||
auto inputVectorY = Opm::cuistl::CuVector<double>(inputDataY.data(), inputDataY.size());
|
||||
auto inputVectorX = Opm::gpuistl::CuVector<double>(inputDataX.data(), inputDataX.size());
|
||||
auto inputVectorY = Opm::gpuistl::CuVector<double>(inputDataY.data(), inputDataY.size());
|
||||
Vector xHost(N), yHost(N);
|
||||
yHost = inputDataY[0];
|
||||
inputVectorX.copyToHost(xHost);
|
||||
|
||||
@@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE(TestDocumentedUsage)
|
||||
{
|
||||
auto someDataOnCPU = std::vector<double>({1.0, 2.0, 42.0, 59.9451743, 10.7132692});
|
||||
|
||||
auto dataOnGPU = ::Opm::cuistl::CuVector<double>(someDataOnCPU);
|
||||
auto dataOnGPU = ::Opm::gpuistl::CuVector<double>(someDataOnCPU);
|
||||
|
||||
// Multiply by 4.0:
|
||||
dataOnGPU *= 4.0;
|
||||
@@ -50,14 +50,14 @@ BOOST_AUTO_TEST_CASE(TestDocumentedUsage)
|
||||
BOOST_AUTO_TEST_CASE(TestConstructionSize)
|
||||
{
|
||||
const int numberOfElements = 1234;
|
||||
auto vectorOnGPU = Opm::cuistl::CuVector<double>(numberOfElements);
|
||||
auto vectorOnGPU = Opm::gpuistl::CuVector<double>(numberOfElements);
|
||||
BOOST_CHECK_EQUAL(numberOfElements, vectorOnGPU.dim());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestCopyFromHostConstructor)
|
||||
{
|
||||
std::vector<double> data {{1, 2, 3, 4, 5, 6, 7}};
|
||||
auto vectorOnGPU = Opm::cuistl::CuVector<double>(data.data(), data.size());
|
||||
auto vectorOnGPU = Opm::gpuistl::CuVector<double>(data.data(), data.size());
|
||||
BOOST_CHECK_EQUAL(data.size(), vectorOnGPU.dim());
|
||||
std::vector<double> buffer(data.size(), 0.0);
|
||||
vectorOnGPU.copyToHost(buffer.data(), buffer.size());
|
||||
@@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(TestCopyFromHostConstructor)
|
||||
BOOST_AUTO_TEST_CASE(TestCopyFromHostFunction)
|
||||
{
|
||||
std::vector<double> data {{1, 2, 3, 4, 5, 6, 7}};
|
||||
auto vectorOnGPU = Opm::cuistl::CuVector<double>(data.size());
|
||||
auto vectorOnGPU = Opm::gpuistl::CuVector<double>(data.size());
|
||||
BOOST_CHECK_EQUAL(data.size(), vectorOnGPU.dim());
|
||||
vectorOnGPU.copyFromHost(data.data(), data.size());
|
||||
std::vector<double> buffer(data.size(), 0.0);
|
||||
@@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(TestCopyFromHostFunction)
|
||||
BOOST_AUTO_TEST_CASE(TestCopyFromBvector)
|
||||
{
|
||||
auto blockVector = Dune::BlockVector<Dune::FieldVector<double, 2>> {{{42, 43}, {44, 45}, {46, 47}}};
|
||||
auto vectorOnGPU = Opm::cuistl::CuVector<double>(blockVector.dim());
|
||||
auto vectorOnGPU = Opm::gpuistl::CuVector<double>(blockVector.dim());
|
||||
vectorOnGPU.copyFromHost(blockVector);
|
||||
std::vector<double> buffer(vectorOnGPU.dim());
|
||||
vectorOnGPU.copyToHost(buffer.data(), buffer.size());
|
||||
@@ -93,7 +93,7 @@ BOOST_AUTO_TEST_CASE(TestCopyToBvector)
|
||||
{
|
||||
std::vector<double> data {{1, 2, 3, 4, 5, 6, 7, 8, 9}};
|
||||
auto blockVector = Dune::BlockVector<Dune::FieldVector<double, 3>>(3);
|
||||
auto vectorOnGPU = Opm::cuistl::CuVector<double>(data.data(), data.size());
|
||||
auto vectorOnGPU = Opm::gpuistl::CuVector<double>(data.data(), data.size());
|
||||
vectorOnGPU.copyToHost(blockVector);
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(TestCopyToBvector)
|
||||
BOOST_AUTO_TEST_CASE(TestDataPointer)
|
||||
{
|
||||
std::vector<double> data {{1, 2, 3, 4, 5, 6, 7, 8, 9}};
|
||||
auto vectorOnGPU = Opm::cuistl::CuVector<double>(data.data(), data.size());
|
||||
auto vectorOnGPU = Opm::gpuistl::CuVector<double>(data.data(), data.size());
|
||||
|
||||
std::vector<double> buffer(data.size(), 0.0);
|
||||
OPM_CUDA_SAFE_CALL(cudaMemcpy(buffer.data(), vectorOnGPU.data(), sizeof(double) * data.size(), cudaMemcpyDeviceToHost));
|
||||
@@ -113,7 +113,7 @@ BOOST_AUTO_TEST_CASE(TestDataPointer)
|
||||
BOOST_AUTO_TEST_CASE(TestCopyScalarMultiply)
|
||||
{
|
||||
std::vector<double> data {{1, 2, 3, 4, 5, 6, 7}};
|
||||
auto vectorOnGPU = Opm::cuistl::CuVector<double>(data.data(), data.size());
|
||||
auto vectorOnGPU = Opm::gpuistl::CuVector<double>(data.data(), data.size());
|
||||
BOOST_CHECK_EQUAL(data.size(), vectorOnGPU.dim());
|
||||
const double scalar = 42.25;
|
||||
vectorOnGPU *= scalar;
|
||||
@@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(TestCopyScalarMultiply)
|
||||
BOOST_AUTO_TEST_CASE(TestTwoNorm)
|
||||
{
|
||||
std::vector<double> data {{1, 2, 3, 4, 5, 6, 7}};
|
||||
auto vectorOnGPU = Opm::cuistl::CuVector<double>(data.data(), data.size());
|
||||
auto vectorOnGPU = Opm::gpuistl::CuVector<double>(data.data(), data.size());
|
||||
auto twoNorm = vectorOnGPU.two_norm();
|
||||
|
||||
double correctAnswer = 0.0;
|
||||
@@ -143,8 +143,8 @@ BOOST_AUTO_TEST_CASE(TestDot)
|
||||
{
|
||||
std::vector<double> dataA {{1, 2, 3, 4, 5, 6, 7}};
|
||||
std::vector<double> dataB {{8, 9, 10, 11, 12, 13, 14}};
|
||||
auto vectorOnGPUA = Opm::cuistl::CuVector<double>(dataA.data(), dataA.size());
|
||||
auto vectorOnGPUB = Opm::cuistl::CuVector<double>(dataB.data(), dataB.size());
|
||||
auto vectorOnGPUA = Opm::gpuistl::CuVector<double>(dataA.data(), dataA.size());
|
||||
auto vectorOnGPUB = Opm::gpuistl::CuVector<double>(dataB.data(), dataB.size());
|
||||
auto dot = vectorOnGPUA.dot(vectorOnGPUB);
|
||||
|
||||
double correctAnswer = 0.0;
|
||||
@@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE(TestDot)
|
||||
BOOST_AUTO_TEST_CASE(Assigment)
|
||||
{
|
||||
std::vector<double> data {{1, 2, 3, 4, 5, 6, 7}};
|
||||
auto vectorOnGPU = Opm::cuistl::CuVector<double>(data.data(), data.size());
|
||||
auto vectorOnGPU = Opm::gpuistl::CuVector<double>(data.data(), data.size());
|
||||
vectorOnGPU = 10.0;
|
||||
vectorOnGPU.copyToHost(data.data(), data.size());
|
||||
|
||||
@@ -171,9 +171,9 @@ BOOST_AUTO_TEST_CASE(Assigment)
|
||||
BOOST_AUTO_TEST_CASE(CopyAssignment)
|
||||
{
|
||||
std::vector<double> data {{1, 2, 3, 4, 5, 6, 7}};
|
||||
auto vectorOnGPU = Opm::cuistl::CuVector<double>(data.data(), data.size());
|
||||
auto vectorOnGPU = Opm::gpuistl::CuVector<double>(data.data(), data.size());
|
||||
vectorOnGPU.copyToHost(data.data(), data.size());
|
||||
auto vectorOnGPUB = Opm::cuistl::CuVector<double>(data.size());
|
||||
auto vectorOnGPUB = Opm::gpuistl::CuVector<double>(data.size());
|
||||
vectorOnGPUB = 4.0;
|
||||
vectorOnGPUB = vectorOnGPU;
|
||||
|
||||
@@ -185,7 +185,7 @@ BOOST_AUTO_TEST_CASE(CopyAssignment)
|
||||
BOOST_AUTO_TEST_CASE(RandomVectors)
|
||||
{
|
||||
|
||||
using GVector = Opm::cuistl::CuVector<double>;
|
||||
using GVector = Opm::gpuistl::CuVector<double>;
|
||||
std::srand(0);
|
||||
std::mt19937 generator;
|
||||
std::uniform_real_distribution<double> distribution(-100.0, 100.0);
|
||||
@@ -268,7 +268,7 @@ BOOST_AUTO_TEST_CASE(RandomVectors)
|
||||
indexSet.push_back(i);
|
||||
}
|
||||
}
|
||||
auto indexSetGPU = Opm::cuistl::CuVector<int>(indexSet);
|
||||
auto indexSetGPU = Opm::gpuistl::CuVector<int>(indexSet);
|
||||
|
||||
aGPU.setZeroAtIndexSet(indexSetGPU);
|
||||
auto projectedA = aGPU.asStdVector();
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
|
||||
using CuViewDouble = ::Opm::cuistl::CuView<double>;
|
||||
using CuBufferDouble = ::Opm::cuistl::CuBuffer<double>;
|
||||
using CuViewDouble = ::Opm::gpuistl::CuView<double>;
|
||||
using CuBufferDouble = ::Opm::gpuistl::CuBuffer<double>;
|
||||
|
||||
__global__ void useCuViewOnGPU(CuViewDouble a, CuViewDouble b){
|
||||
b[0] = a.front();
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestToIntThrowsOutofRange)
|
||||
{
|
||||
BOOST_CHECK_THROW(Opm::cuistl::detail::to_int(size_t(std::numeric_limits<int>::max()) + size_t(1));
|
||||
BOOST_CHECK_THROW(Opm::gpuistl::detail::to_int(size_t(std::numeric_limits<int>::max()) + size_t(1));
|
||||
, std::invalid_argument);
|
||||
}
|
||||
|
||||
@@ -33,26 +33,26 @@ BOOST_AUTO_TEST_CASE(TestToIntConvertInRange)
|
||||
{
|
||||
// This might seem slow, but it is really fast:
|
||||
for (size_t i = 0; i <= size_t(1024 * 1024); ++i) {
|
||||
BOOST_CHECK_EQUAL(int(i), Opm::cuistl::detail::to_int(i));
|
||||
BOOST_CHECK_EQUAL(int(i), Opm::gpuistl::detail::to_int(i));
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL(std::numeric_limits<int>::max(),
|
||||
Opm::cuistl::detail::to_int(size_t(std::numeric_limits<int>::max())));
|
||||
Opm::gpuistl::detail::to_int(size_t(std::numeric_limits<int>::max())));
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestToSizeTThrowsOutofRange)
|
||||
{
|
||||
BOOST_CHECK_THROW(Opm::cuistl::detail::to_size_t(-1);, std::invalid_argument);
|
||||
BOOST_CHECK_THROW(Opm::gpuistl::detail::to_size_t(-1);, std::invalid_argument);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestToSizeTConvertInRange)
|
||||
{
|
||||
// This might seem slow, but it is really fast:
|
||||
for (int i = 0; i <= 1024 * 1024; ++i) {
|
||||
BOOST_CHECK_EQUAL(size_t(i), Opm::cuistl::detail::to_size_t(i));
|
||||
BOOST_CHECK_EQUAL(size_t(i), Opm::gpuistl::detail::to_size_t(i));
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL(size_t(std::numeric_limits<int>::max()),
|
||||
Opm::cuistl::detail::to_size_t(std::numeric_limits<int>::max()));
|
||||
Opm::gpuistl::detail::to_size_t(std::numeric_limits<int>::max()));
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ using Matrix = Dune::BCRSMatrix<Dune::FieldMatrix<double, dim, dim>>;
|
||||
using Vector = Dune::BlockVector<Dune::FieldVector<double, dim>>;
|
||||
using Moperator = Dune::MatrixAdapter<Matrix, Vector, Vector>;
|
||||
using PrecondFactory = Opm::PreconditionerFactory<Moperator, Dune::Amg::SequentialInformation>;
|
||||
using SolverAdapter = Opm::cuistl::SolverAdapter<Moperator, Dune::BiCGSTABSolver, Vector>;
|
||||
using SolverAdapter = Opm::gpuistl::SolverAdapter<Moperator, Dune::BiCGSTABSolver, Vector>;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user