From 0da4cd55aac1a0e6f0dba59be34151660833354e Mon Sep 17 00:00:00 2001
From: Philipp Suffa <philipp.suffa@fau.de>
Date: Wed, 24 Jan 2024 15:57:50 +0100
Subject: [PATCH] Allow multiGPU by setting correct device to MPI process[skip
 ci]

---
 apps/tutorials/sycl/SYCLTest.cpp | 16 +++++++++++++---
 apps/tutorials/sycl/SYCLTest.prm |  2 +-
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/apps/tutorials/sycl/SYCLTest.cpp b/apps/tutorials/sycl/SYCLTest.cpp
index 84799ef2a..5d6d717bb 100644
--- a/apps/tutorials/sycl/SYCLTest.cpp
+++ b/apps/tutorials/sycl/SYCLTest.cpp
@@ -142,8 +142,19 @@ int main(int argc, char** argv)
    auto blocks = blockforest::createUniformBlockGridFromConfig(walberlaEnv.config());
 #if defined(WALBERLA_BUILD_WITH_SYCL)
    WALBERLA_LOG_PROGRESS("Create SYCL queue")
-   auto syclQueue = make_shared<sycl::queue> (sycl::default_selector_v);
-   WALBERLA_LOG_INFO("Running SYCL for MPI process " << mpi::MPIManager::instance()->worldRank() << " on " << (*syclQueue).get_device().get_info<cl::sycl::info::device::name>())
+   auto mpiRank = mpi::MPIManager::instance()->worldRank();
+
+   //FOR MULTI GPU
+   std::vector<sycl::device> Devs;
+   for (const auto &plt : sycl::platform::get_platforms()) {
+      if (plt.get_backend() == sycl::backend::ext_oneapi_cuda)
+         Devs.push_back(plt.get_devices()[0]);
+   }
+   auto syclQueue = make_shared<sycl::queue> (Devs[mpiRank]);
+
+   //FOR  CPU
+   //auto syclQueue = make_shared<sycl::queue> (sycl::default_selector_v);
+   WALBERLA_LOG_INFO("Running SYCL for MPI process " << mpiRank << " on " << (*syclQueue).get_device().get_info<cl::sycl::info::device::name>())
    //WALBERLA_LOG_INFO("Max hardware threads are " << sycl::default_selector().select_device().get_info<sycl::info::device::max_compute_units>());
    blocks->setSYCLQueue(syclQueue);
 #endif
@@ -239,7 +250,6 @@ int main(int argc, char** argv)
 
    // Timeloop
    if (timestepStrategy == "fullSim") {
-      communication();
       timeloop.add() << BeforeFunction(communication, "communication") << Sweep(deviceSyncWrapper(SYCLTestSweep), "SYCL Sweep");
    }
    else if (timestepStrategy == "kernelOnly") {
diff --git a/apps/tutorials/sycl/SYCLTest.prm b/apps/tutorials/sycl/SYCLTest.prm
index 73f1352b4..d00842918 100644
--- a/apps/tutorials/sycl/SYCLTest.prm
+++ b/apps/tutorials/sycl/SYCLTest.prm
@@ -22,7 +22,7 @@ ShearFlowSetup
 
 DomainSetup
 {
-   blocks        <  1,    1, 1 >;
+   blocks        <  2,    1, 1 >;
    cellsPerBlock <  1000, 1000, 1 >;
    periodic      <  0,    0, 0 >;
    oneBlockPerProcess      true;
-- 
GitLab