Arcane  v4.1.4.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 std::cout << "INIT_ACCELERATOR use?=" << use_accelerator << "\n";
60 if (use_accelerator) {
61 AcceleratorRuntimeInitialisationInfo init_info;
62 String default_runtime_name;
63#if defined(ARCCORE_HAS_CUDA)
64 default_runtime_name = "cuda";
65#elif defined(ARCCORE_HAS_HIP)
66 default_runtime_name = "hip";
67#elif defined(ARCCORE_HAS_SYCL)
68 default_runtime_name = "sycl";
69#endif
70
71 String dll_full_path = Platform::getLoadedSharedLibraryFullPath("arccore_accelerator");
72 String library_path;
73 if (!dll_full_path.null())
74 library_path = Platform::getFileDirName(dll_full_path);
75 if (library_path.null())
76 library_path = Platform::getCurrentDirectory();
77
78 std::cout << "INIT_ACCELERATOR default_runtime=" << default_runtime_name << " lib_path=" << library_path << "\n";
79 bool has_accelerator = false;
80 init_info.setIsUsingAcceleratorRuntime(true);
81 int r = Impl::RuntimeLoader::loadRuntime(init_info, default_runtime_name, library_path, has_accelerator);
82 if (r == 0) {
83 if (Impl::isUsingCUDARuntime())
84 m_policy = eExecutionPolicy::CUDA;
85 else if (Impl::isUsingHIPRuntime())
86 m_policy = eExecutionPolicy::HIP;
87 else if (Impl::isUsingSYCLRuntime())
88 m_policy = eExecutionPolicy::SYCL;
89 }
90 }
91 {
92 m_concurrency_application.setTraceMng(m_trace_mng);
93 m_application_build_info.setDefaultValues();
94 m_application_build_info.setDefaultServices();
95 if (max_allowed_thread > 1)
96 m_application_build_info.setNbTaskThread(max_allowed_thread);
97 {
98 const auto& b = m_application_build_info;
99 auto task_names = _stringListToCoreArray(b.taskImplementationServices());
100 auto thread_names = _stringListToCoreArray(b.threadImplementationServices());
101 Int32 nb_task_thread = b.nbTaskThread();
102 ConcurrencyApplicationBuildInfo c(task_names.constView(), thread_names.constView(), nb_task_thread);
103 m_concurrency_application.setCoreServices(c);
104 }
105 if (max_allowed_thread > 1)
106 m_policy = eExecutionPolicy::Thread;
107 }
108}
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
112
113Initializer::
114~Initializer() noexcept(false)
115{
116 Accelerator::RunnerInternal::finalize(nullptr);
117}
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
122} // namespace Arcane::Accelerator
123
124/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
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.