| 223 | #endif |
| 224 | |
| 225 | void |
| 226 | Device::Initialize (bool minimal, int a_device_id) |
| 227 | { |
| 228 | amrex::ignore_unused(minimal, a_device_id); |
| 229 | #ifdef AMREX_USE_GPU |
| 230 | |
| 231 | #if defined(AMREX_USE_CUDA) && (defined(AMREX_PROFILING) || defined(AMREX_TINY_PROFILING)) |
| 232 | // Wrap cuda init to identify it appropriately in nvvp. |
| 233 | // Note: first substantial cuda call may cause a lengthy |
| 234 | // cuda API and cuda driver API initialization that will |
| 235 | // be captured by the profiler. It a necessary, system |
| 236 | // dependent step that is unavoidable. |
| 237 | nvtxRangePush("initialize_device"); |
| 238 | #endif |
| 239 | |
| 240 | ParmParse ppamrex("amrex"); |
| 241 | ppamrex.queryAdd("max_gpu_streams", max_gpu_streams); |
| 242 | max_gpu_streams = std::min(max_gpu_streams, AMREX_GPU_MAX_STREAMS); |
| 243 | max_gpu_streams = std::max(max_gpu_streams, 1); |
| 244 | |
| 245 | ParmParse pp("device"); |
| 246 | if (! pp.query("verbose", "v", verbose)) { |
| 247 | pp.add("verbose", verbose); |
| 248 | } |
| 249 | |
| 250 | if (amrex::Verbose()) { |
| 251 | AMREX_HIP_OR_CUDA_OR_SYCL |
| 252 | ( amrex::Print() << "Initializing HIP...\n";, |
| 253 | amrex::Print() << "Initializing CUDA...\n";, |
| 254 | amrex::Print() << "Initializing SYCL...\n"; ) |
| 255 | } |
| 256 | |
| 257 | // Count the number of GPU devices. |
| 258 | int gpu_device_count = 0; |
| 259 | #ifdef AMREX_USE_SYCL |
| 260 | { |
| 261 | sycl::platform platform(sycl::gpu_selector_v); |
| 262 | auto const& gpu_devices = platform.get_devices(); |
| 263 | gpu_device_count = gpu_devices.size(); |
| 264 | if (gpu_device_count <= 0) { |
| 265 | amrex::Abort("No GPU device found"); |
| 266 | } |
| 267 | } |
| 268 | #else |
| 269 | AMREX_HIP_OR_CUDA(AMREX_HIP_SAFE_CALL (hipGetDeviceCount(&gpu_device_count));, |
| 270 | AMREX_CUDA_SAFE_CALL(cudaGetDeviceCount(&gpu_device_count)); ); |
| 271 | if (gpu_device_count <= 0) { |
| 272 | amrex::Abort("No GPU device found"); |
| 273 | } |
| 274 | #endif |
| 275 | |
| 276 | // Now, assign ranks to GPUs. If we only have one GPU, |
| 277 | // or only one MPI rank, this is easy. Otherwise, we |
| 278 | // need to do a little more work. |
| 279 | |
| 280 | int n_local_procs = 1; |
| 281 | amrex::ignore_unused(n_local_procs); |
| 282 |
nothing calls this directly
no test coverage detected