From 32dd41a728ce10113032e20955ba08f8de449857 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 12 Sep 2021 14:01:55 +0200 Subject: Start using C++ cuda-api-wrapper instead of raw CUDA --- tangle/benchmark-ldc.cu | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'tangle/benchmark-ldc.cu') diff --git a/tangle/benchmark-ldc.cu b/tangle/benchmark-ldc.cu index 1400547..18b30d1 100644 --- a/tangle/benchmark-ldc.cu +++ b/tangle/benchmark-ldc.cu @@ -12,7 +12,7 @@ using T = float; using DESCRIPTOR = descriptor::D3Q19; void simulate(descriptor::Cuboid cuboid, std::size_t nStep) { - cudaSetDevice(0); + auto current = cuda::device::current::get(); Lattice lattice(cuboid); @@ -30,7 +30,7 @@ void simulate(descriptor::Cuboid cuboid, std::size_t nStep) { auto box_mask = materials.mask_of_material(2); auto lid_mask = materials.mask_of_material(3); - cudaDeviceSynchronize(); + cuda::synchronize(current); for (std::size_t iStep=0; iStep < 100; ++iStep) { lattice.apply(Operator(BgkCollideO(), bulk_mask, 0.56), @@ -39,7 +39,7 @@ void simulate(descriptor::Cuboid cuboid, std::size_t nStep) { lattice.stream(); } - cudaDeviceSynchronize(); + cuda::synchronize(current); auto start = timer::now(); @@ -50,7 +50,7 @@ void simulate(descriptor::Cuboid cuboid, std::size_t nStep) { lattice.stream(); } - cudaDeviceSynchronize(); + cuda::synchronize(current); auto mlups = timer::mlups(cuboid.volume, nStep, start); @@ -58,6 +58,10 @@ void simulate(descriptor::Cuboid cuboid, std::size_t nStep) { } int main(int argc, char* argv[]) { + if (cuda::device::count() == 0) { + std::cerr << "No CUDA devices on this system" << std::endl; + return -1; + } if (argc != 3) { std::cerr << "Invalid parameter count" << std::endl; return -1; -- cgit v1.2.3