Arcane  v4.1.7.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-2026 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-2026 */
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#include "arccore/base/CoreArray.h"
19
20#include "arccore/common/List.h"
21#include "arccore/common/accelerator/internal/AcceleratorCoreGlobalInternal.h"
22#include "arccore/common/accelerator/internal/RuntimeLoader.h"
23#include "arccore/common/accelerator/internal/RunnerInternal.h"
24#include "arccore/common/accelerator/AcceleratorRuntimeInitialisationInfo.h"
25
26#include <iostream>
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31namespace Arcane
32{
33namespace
34{
36 _stringListToCoreArray(const StringList& slist)
37 {
39 for (const String& s : slist)
40 a.add(s);
41 return a;
42 }
43} // namespace
44} // namespace Arcane
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
49namespace Arcane::Accelerator
50{
51
52/*---------------------------------------------------------------------------*/
53/*---------------------------------------------------------------------------*/
54
55Initializer::
56Initializer(bool use_accelerator, Int32 max_allowed_thread)
57: m_trace_mng(arccoreCreateDefaultTraceMng())
58{
59 const bool is_verbose = false;
60 if (is_verbose)
61 std::cout << "INIT_ACCELERATOR use?=" << use_accelerator << "\n";
62 if (use_accelerator) {
63 AcceleratorRuntimeInitialisationInfo init_info;
64 String default_runtime_name;
65#if defined(ARCCORE_HAS_CUDA)
66 default_runtime_name = "cuda";
67#elif defined(ARCCORE_HAS_HIP)
68 default_runtime_name = "hip";
69#elif defined(ARCCORE_HAS_SYCL)
70 default_runtime_name = "sycl";
71#endif
72
73 String dll_full_path = Platform::getLoadedSharedLibraryFullPath("arccore_accelerator");
74 String library_path;
75 if (!dll_full_path.null())
76 library_path = Platform::getFileDirName(dll_full_path);
77 if (library_path.null())
78 library_path = Platform::getCurrentDirectory();
79
80 if (is_verbose)
81 std::cout << "INIT_ACCELERATOR default_runtime=" << default_runtime_name << " lib_path=" << library_path << "\n";
82 bool has_accelerator = false;
83 init_info.setIsUsingAcceleratorRuntime(true);
84 int r = Impl::RuntimeLoader::loadRuntime(init_info, default_runtime_name, library_path, has_accelerator);
85 if (r == 0) {
86 if (Impl::isUsingCUDARuntime())
87 m_policy = eExecutionPolicy::CUDA;
88 else if (Impl::isUsingHIPRuntime())
89 m_policy = eExecutionPolicy::HIP;
90 else if (Impl::isUsingSYCLRuntime())
91 m_policy = eExecutionPolicy::SYCL;
92 }
93 }
94 {
95 m_concurrency_application.setTraceMng(m_trace_mng);
96 m_application_build_info.setDefaultValues();
97 m_application_build_info.setDefaultServices();
98 if (max_allowed_thread > 1)
99 m_application_build_info.setNbTaskThread(max_allowed_thread);
100 {
101 const auto& b = m_application_build_info;
102 auto task_names = _stringListToCoreArray(b.taskImplementationServices());
103 auto thread_names = _stringListToCoreArray(b.threadImplementationServices());
104 Int32 nb_task_thread = b.nbTaskThread();
105 ConcurrencyApplicationBuildInfo c(task_names.constView(), thread_names.constView(), nb_task_thread);
106 m_concurrency_application.setCoreServices(c);
107 }
108 // Si la politique d'exécution n'est pas positionnée, alors ce sera le multi-threading
109 if (max_allowed_thread > 1 && m_policy == eExecutionPolicy::Sequential)
110 m_policy = eExecutionPolicy::Thread;
111 }
112}
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
116
117Initializer::
118~Initializer() noexcept(false)
119{
120 Accelerator::RunnerInternal::finalize(nullptr);
121}
122
123/*---------------------------------------------------------------------------*/
124/*---------------------------------------------------------------------------*/
125
126} // namespace Arcane::Accelerator
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
Chaîne de caractères unicode.
Espace de nom pour l'utilisation des accélérateurs.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
List< String > StringList
Tableau de chaînes de caractères unicode.
Definition UtilsTypes.h:509
std::int32_t Int32
Type entier signé sur 32 bits.