Arcane  v4.1.2.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
Initializer.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Initializer.h (C) 2000-2025 */
9/* */
10/* Classe pour initialiser le runtime accélérateur. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/accelerator/internal/Initializer.h"
15
16#include "arccore/base/String.h"
17#include "arccore/base/PlatformUtils.h"
18
19#include "arccore/common/accelerator/internal/AcceleratorCoreGlobalInternal.h"
20#include "arccore/common/accelerator/internal/RuntimeLoader.h"
21#include "arccore/common/accelerator/AcceleratorRuntimeInitialisationInfo.h"
22
23#include <iostream>
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane::Accelerator
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33Initializer::
34Initializer(bool use_accelerator, Int32 max_allowed_thread)
35{
36 std::cout << "INIT_ACCELERATOR use?=" << use_accelerator << "\n";
37 if (use_accelerator) {
39 String default_runtime_name;
40#if defined(ARCCORE_HAS_CUDA)
41 default_runtime_name = "cuda";
42#elif defined(ARCCORE_HAS_HIP)
43 default_runtime_name = "hip";
44#elif defined(ARCCORE_HAS_SYCL)
45 default_runtime_name = "sycl";
46#endif
47
48 String dll_full_path = Platform::getLoadedSharedLibraryFullPath("arccore_accelerator");
49 String library_path;
50 if (!dll_full_path.null())
51 library_path = Platform::getFileDirName(dll_full_path);
52 if (library_path.null())
53 library_path = Platform::getCurrentDirectory();
54
55 std::cout << "INIT_ACCELERATOR default_runtime=" << default_runtime_name << " lib_path=" << library_path << "\n";
56 bool has_accelerator = false;
57 init_info.setIsUsingAcceleratorRuntime(true);
58 int r = Impl::RuntimeLoader::loadRuntime(init_info, default_runtime_name, library_path, has_accelerator);
59 if (r == 0) {
60 if (Impl::isUsingCUDARuntime())
61 m_policy = eExecutionPolicy::CUDA;
62 else if (Impl::isUsingHIPRuntime())
63 m_policy = eExecutionPolicy::HIP;
64 else if (Impl::isUsingHIPRuntime())
65 m_policy = eExecutionPolicy::SYCL;
66 }
67 }
68}
69
70/*---------------------------------------------------------------------------*/
71/*---------------------------------------------------------------------------*/
72
73} // namespace Arcane::Accelerator
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
Espace de nom pour l'utilisation des accélérateurs.
@ SYCL
Politique d'exécution utilisant l'environnement SYCL.
@ HIP
Politique d'exécution utilisant l'environnement HIP.
@ CUDA
Politique d'exécution utilisant l'environnement CUDA.
String getFileDirName(const String &file_name)
Retourne le nom du répertoire d'un fichier.
String getCurrentDirectory()
Chemin du répertoire courant.
String getLoadedSharedLibraryFullPath(const String &dll_name)
Retourne le chemin complet d'une bibliothèque dynamique chargée.
std::int32_t Int32
Type entier signé sur 32 bits.