14#include "arccore/common/accelerator/internal/RuntimeLoader.h"
16#include "arccore/base/PlatformUtils.h"
17#include "arccore/base/FatalErrorException.h"
18#include "arccore/base/internal/IDynamicLibraryLoader.h"
22#include "arccore/common/internal/MemoryUtilsInternal.h"
23#include "arccore/common/accelerator/AcceleratorRuntimeInitialisationInfo.h"
24#include "arccore/common/accelerator/internal/RegisterRuntimeInfo.h"
29namespace Arcane::Accelerator::Impl
50 const String& default_runtime_name,
51 const String& library_path,
52 bool& has_accelerator)
54 has_accelerator =
false;
56 if (!init_info.isUsingAcceleratorRuntime())
58 String runtime_name = init_info.acceleratorRuntime();
59 if (runtime_name ==
"sequential")
61 if (runtime_name.
empty())
62 runtime_name = default_runtime_name;
63 if (runtime_name.
empty())
68 if (runtime_name !=
"cuda" && runtime_name !=
"hip" && runtime_name !=
"sycl")
69 ARCCORE_FATAL(
"Invalid accelerator runtime '{0}'. Only 'cuda', 'hip' or 'sycl' is allowed", runtime_name);
79 String os_dir(library_path);
80 String dll_name =
"arccore_accelerator_" + runtime_name +
"_runtime";
81 String symbol_name =
"arcaneRegisterAcceleratorRuntime" + runtime_name;
84 ARCCORE_FATAL(
"Can not found dynamic library '{0}' for using accelerator runtime", dll_name);
86 bool is_found =
false;
88 if (!is_found || !functor_addr)
89 ARCCORE_FATAL(
"Can not find symbol '{0}' in library '{1}'", symbol_name, dll_name);
91 auto my_functor =
reinterpret_cast<ArcaneAutoDetectAcceleratorFunctor
>(functor_addr);
95 if (!verbose_str.
null())
96 runtime_info.setVerbose(
true);
98 (*my_functor)(runtime_info);
99 has_accelerator =
true;
103 if (!data_allocator_str.
null()) {
112 catch (
const std::exception& ex) {
#define ARCCORE_FATAL(...)
Macro throwing a FatalErrorException.
Utility functions for exception handling.
Int32 print(ITraceMng *tm, bool is_no_continue=true)
Prints a message for an unknown exception.
Memory management utility functions.
Information for accelerator initialization.
void setAcceleratorRuntime(StringView name)
Name of the runtime used (for now only 'cuda', 'hip' or 'sycl').
static int loadRuntime(AcceleratorRuntimeInitialisationInfo &init_info, const String &default_runtime_name, const String &library_path, bool &has_accelerator)
Detects and loads the accelerator runtime management library.
Information to initialize the accelerator runtime.
Base class for an exception.
Interface of a dynamic library loader.
static IDynamicLibraryLoader * getDefault()
Service used for dynamically loading libraries.
Interface of a dynamic library.
virtual void * getSymbolAddress(const String &symbol_name, bool *is_found)=0
Returns the address of the symbol named symbol_name.
Unicode character string.
bool null() const
Returns true if the string is null.
bool empty() const
True if the string is empty (null or "").
void setDefaultDataMemoryResource(eMemoryResource mem_resource)
Sets the memory resource used for the data memory allocator.
eMemoryResource getMemoryResourceFromName(const String &name)
Returns the memory resource by its name.
eMemoryResource
List of available memory resources.
@ Unknown
Unknown or uninitialized value.