-
Notifications
You must be signed in to change notification settings - Fork 16.4k
[OFFLOAD] Add plugin with support for Intel oneAPI Level Zero #158900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
133 commits
Select commit
Hold shift + click to select a range
0c42764
[OFFLOAD] Add plugin with support for Intel Level Zero
adurang e8c471e
Merge branch 'main' into l0_plugin
adurang f8956cd
Update offload/CMakeLists.txt
adurang d3fc4d7
Update offload/plugins-nextgen/level_zero/CMakeLists.txt
adurang 4b38386
Update offload/plugins-nextgen/level_zero/include/L0Plugin.h
adurang 6c1c820
Replace pragma once
adurang fd91c47
Address review comments
adurang 84665dc
Fix makefile format
adurang a2217db
change to StringRef in multiple places
adurang 08880a6
remove tokenize
adurang 9a3088c
remove unused code
adurang 24d0645
fix format
adurang 0eb5712
Remove environment variable
adurang f491f3d
fix getAsInteger conditions
adurang 9bbdae3
Merge branch 'main' into l0_plugin
adurang fe633f4
Don't use __tgt_device_image
adurang e36a8fc
fix image checking
adurang 53bce7e
changes from review comments
adurang 69df388
remove more CMake messages
adurang 91fa069
format
adurang 561e4ca
remove unnecessary check
adurang ad07ee8
Merge branch 'main' into l0_plugin
adurang 5b90ccb
Add level_zero to liboffload platforms
adurang 6b8280d
fix different issues
adurang f983135
Fix ELF bits from #159623
adurang b6c393a
format & add more Deviceinfo tags
adurang b226c70
tidy up Makefile
adurang af1945f
format & renaming
adurang 3dba3c3
Remove ompt_device_t reference
adurang ac62231
address reviews
adurang 17c8e31
remove unused argument
adurang e550bf1
Merge branch 'main' into l0_plugin
adurang b859179
cleanup
adurang f1d1aad
[OFFLOAD] Enable level zero testing
adurang c141f9d
address review
adurang dd774b6
fix & remove dead code
adurang 7fa9dda
remove support for target ICVs
adurang 96411ce
typo & format
adurang a4cd814
Merge branch 'main' into l0_plugin
adurang 6c5278f
Adjust interfaces after merge
adurang 44b2f48
push some error checking down
adurang b4e238f
Update offload/plugins-nextgen/level_zero/include/L0Device.h
adurang 166028d
address review comments
adurang 6629159
format
adurang c00c288
more format :/
adurang 93d3948
add missed wrapper; remove unused macro
adurang 4a2140e
Remove level_zero from default plugin list
adurang 94335ac
Merge branch 'main' into l0_plugin
adurang bd43212
remove removed plugin interface
adurang 2be5a5a
Merge branch 'l0_plugin' into l0_tests
adurang 7f9c0c8
update spirv target
adurang 2d7cc66
address some reviews
adurang 987f44c
[OFFLOAD] Add support for indexed per-thread containers
adurang 91e51ed
address more reviews
adurang 12ab478
address more comments
adurang 3287b1a
change some containers
adurang 69abec0
more container changes
adurang b7e95ab
move unsafe code out of destructors
adurang 91f1033
Remove legacy error checking Pt 1
adurang 1221006
Remove legacy error checking Pt 2
adurang 45d38a2
Remove legacy error checking Pt 3
adurang 6ec68e7
Remove legacy error checking Pt 4
adurang ef8d794
Add more error checking
adurang 19e888e
fix format
adurang a591b0e
Move DeviceRange to PluginInterface and remove internal Device list
adurang fc61165
refactor MemPool options field
adurang 40f2626
change auto returns
adurang f04fef7
Remove link copy queues
adurang e95cab5
Merge branch 'main' into extend_ptt
jhuber6 e0c46a6
Change container
adurang 0d3d6dc
Add deinit method
adurang 2de9273
renaming variables, remove some locks
adurang f4e89a9
format
adurang 5ebf0a4
more renaming
adurang 8bff29d
forgot one mutex
adurang d29eac0
missed one container
adurang 4a6b196
debug build fixes
adurang caedd4d
remove auto
adurang 01f9c44
missed one
adurang e80dcf9
Some renaming
adurang 5451f22
Add asserts
adurang 120e3d4
fixes and cleanup
adurang 40ad342
format :/
adurang 8bb25ad
fixes
adurang 08d5f32
fix incorrect memory logging and MemPool small refactor
adurang ba08709
Refactor code from comments
adurang 69c0db3
Restructure kernel launching code
adurang ba0ac45
Remove unused code
adurang 32b9b59
Use correct thread information
adurang b44f992
format
adurang a14ee62
Fix asserts to not be undefined
adurang e1dfd79
Fix env var parsing issue
adurang 21effca
Merge branch 'extend_ptt' into l0_plugin
adurang 581b952
Merge branch 'main' into l0_plugin
adurang 045c94c
add isAccessiblePtrImpl to L0Device
adurang fd15e04
fixes
adurang 827b28c
format
adurang 26a1231
fix
adurang e2b8523
make kernel properties mutable; remove unused field
adurang bd364c5
Implement a few additional services
adurang 0f59337
minor change
adurang 579264a
minor refactoring
adurang 26fbcc0
Refactor container concepts checks
adurang 32819df
remove clearAll
adurang 2d4f364
Simplify PerThreadData
adurang 9c602be
Merge branch 'extend_ptt' into l0_plugin
adurang bc0ccaf
fix
adurang fd38f8d
Address comments
adurang 9c5942e
fix comments
adurang 8160235
Merge branch 'extend_ptt' into l0_plugin
adurang 1cadfb8
Merge branch 'main' into l0_plugin
adurang 6f850c2
adjust to removal of memory pool
adurang 3f78a5a
cleanup L0ThreadTLS
adurang 1b98333
use std::bitset to track AsyncQueues
adurang f2c2c32
address comments to changes in PluginInterface
adurang 2623a9f
change usages of *INT_MAX to use numeric_limits
adurang b76ef59
remove level_zero from pluginNameToBackend
adurang 8caa36d
remove level_zero from liboffload
adurang 7ad1982
fix typo
adurang 7e9e2f4
Make a constant for timeout expression
adurang 2e820be
address comments
adurang e613b16
address comments
adurang 9a10b71
format
adurang 2b5b460
address comments
adurang 6556a10
Address comments
adurang 0aa85d5
remove some macros
adurang 88b8091
remove unusued macro
adurang be26aac
remove str macro
adurang 7093e7b
Fix comments punctuation Pt.1
adurang 2d5430c
Fix comments punctuation Pt.2
adurang 12e4bda
Simplify getDevicesRange
adurang 45a62df
space
adurang bc28628
Fix level zero library name
adurang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Create the library and add the default arguments. | ||
| add_target_library(omptarget.rtl.level_zero LEVEL_ZERO) | ||
|
|
||
| set(LEVEL_ZERO_SRC_FILES | ||
| src/L0Context.cpp | ||
| src/L0Device.cpp | ||
| src/L0Kernel.cpp | ||
| src/L0Memory.cpp | ||
| src/L0Program.cpp | ||
| src/L0Plugin.cpp | ||
| src/L0Program.cpp | ||
| src/L0Options.cpp | ||
| ) | ||
|
|
||
| target_sources(omptarget.rtl.level_zero PRIVATE | ||
| ${LEVEL_ZERO_SRC_FILES} | ||
| ) | ||
|
|
||
| target_include_directories(omptarget.rtl.level_zero PRIVATE | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/include | ||
| ) | ||
|
|
||
| target_include_directories(omptarget.rtl.level_zero PRIVATE | ||
| ${LIBOMPTARGET_INCLUDE_DIR} | ||
| ${LIBOMPTARGET_DEP_LEVEL_ZERO_INCLUDE_DIR} | ||
| ${LIBOMPTARGET_LLVM_INCLUDE_DIRS} | ||
| ${LIBOMPTARGET_OMP_HEADER_DIR} | ||
| ) | ||
|
|
||
| if (EXISTS ${LIBOMPTARGET_DEP_LEVEL_ZERO_LIBRARY} AND NOT "level_zero" IN_LIST LIBOMPTARGET_DLOPEN_PLUGINS) | ||
| message(STATUS "Building Level Zero NG plugin linked against level_zero library") | ||
| if(UNIX) | ||
| target_link_libraries(omptarget.rtl.level_zero PRIVATE | ||
| ${LIBOMPTARGET_DEP_LEVEL_ZERO_LIBRARY}) | ||
| elseif(WIN32) | ||
| # Full path to the Level Zero library is recognized as a linker option, so we | ||
| # separate directory and file name | ||
| cmake_path(GET LIBOMPTARGET_DEP_LEVEL_ZERO_LIBRARY FILENAME LEVEL_ZERO_LIBRARY_NAME) | ||
| cmake_path(GET LIBOMPTARGET_DEP_LEVEL_ZERO_LIBRARY PARENT_PATH LEVEL_ZERO_LIBRARY_PATH) | ||
| target_link_libraries(omptarget.rtl.level_zero PRIVATE ${LEVEL_ZERO_LIBRARY_NAME} | ||
| ${LIBOMP_LIB_FILE}) | ||
| target_link_directories(omptarget.rtl.level_zero PRIVATE ${LEVEL_ZERO_LIBRARY_PATH}) | ||
| else() | ||
| message(FATAL_ERROR "Missing platform support") | ||
| endif() | ||
| else() | ||
| message(STATUS "Building Level Zero NG plugin for dlopened level_zero") | ||
| target_sources(omptarget.rtl.level_zero PRIVATE src/L0DynWrapper.cpp) | ||
| endif() | ||
|
|
||
| option(LIBOMPTARGET_FORCE_LEVELZERO_TESTS "Build Level Zero libomptarget tests" OFF) | ||
| if (LIBOMPTARGET_FOUND_INTELGPU_GPU OR LIBOMPTARGET_FORCE_LEVELZERO_TESTS) | ||
| # Report to the parent scope that we are building a plugin for intelgpu | ||
| set(LIBOMPTARGET_SYSTEM_TARGETS | ||
| "${LIBOMPTARGET_SYSTEM_TARGETS} spirv64-intel" PARENT_SCOPE) | ||
| list(APPEND LIBOMPTARGET_TESTED_PLUGINS "omptarget.rtl.level_zero") | ||
| set(LIBOMPTARGET_TESTED_PLUGINS "${LIBOMPTARGET_TESTED_PLUGINS}" PARENT_SCOPE) | ||
| else() | ||
| message(STATUS "Not generating Level Zero tests, no supported devices detected." | ||
| " Use 'LIBOMPTARGET_FORCE_INTELGPU_TESTS' to override.") | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| //===--- Level Zero Target RTL Implementation -----------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Async Queue wrapper for Level Zero. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_ASYNCQUEUE_H | ||
| #define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_ASYNCQUEUE_H | ||
|
|
||
| #include <tuple> | ||
|
|
||
| #include "L0Memory.h" | ||
|
|
||
| namespace llvm::omp::target::plugin { | ||
|
|
||
| /// Abstract queue that supports asynchronous command submission. | ||
| struct AsyncQueueTy { | ||
| /// List of events attached to submitted commands. | ||
| llvm::SmallVector<ze_event_handle_t> WaitEvents; | ||
| /// Pending staging buffer to host copies. | ||
| llvm::SmallVector<std::tuple<void *, void *, size_t>> H2MList; | ||
| /// Pending USM memory copy commands that must wait for kernel completion. | ||
| llvm::SmallVector<std::tuple<const void *, void *, size_t>> USM2MList; | ||
| /// Kernel event not signaled. | ||
| ze_event_handle_t KernelEvent = nullptr; | ||
| /// Clear data. | ||
| void reset() { | ||
| WaitEvents.clear(); | ||
| H2MList.clear(); | ||
| USM2MList.clear(); | ||
| KernelEvent = nullptr; | ||
| } | ||
| }; | ||
|
|
||
| using AsyncQueuePoolTy = ObjPool<AsyncQueueTy>; | ||
|
|
||
| } // namespace llvm::omp::target::plugin | ||
| #endif // OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_ASYNCQUEUE_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| //===--- Level Zero Target RTL Implementation -----------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Level Zero Context abstraction. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0CONTEXT_H | ||
| #define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0CONTEXT_H | ||
|
|
||
| #include "L0Memory.h" | ||
| #include "PerThreadTable.h" | ||
|
|
||
| namespace llvm::omp::target::plugin { | ||
|
|
||
| class LevelZeroPluginTy; | ||
|
|
||
| class L0ContextTLSTy { | ||
| StagingBufferTy StagingBuffer; | ||
|
|
||
| public: | ||
| StagingBufferTy &getStagingBuffer() { return StagingBuffer; } | ||
| const StagingBufferTy &getStagingBuffer() const { return StagingBuffer; } | ||
|
|
||
| Error deinit() { return StagingBuffer.clear(); } | ||
| }; | ||
|
|
||
| struct L0ContextTLSTableTy | ||
| : public PerThreadContainer< | ||
| std::unordered_map<ze_context_handle_t, L0ContextTLSTy>> { | ||
| Error deinit() { | ||
| return PerThreadTable::deinit( | ||
| [](L0ContextTLSTy &Entry) -> auto { return Entry.deinit(); }); | ||
| } | ||
| }; | ||
|
|
||
| /// Driver and context-specific resources. We assume a single context per | ||
| /// driver. | ||
| class L0ContextTy { | ||
| /// The plugin that created this context. | ||
| LevelZeroPluginTy &Plugin; | ||
|
|
||
| /// Level Zero Driver handle. | ||
| ze_driver_handle_t zeDriver = nullptr; | ||
|
|
||
| /// Common Level Zero context. | ||
| ze_context_handle_t zeContext = nullptr; | ||
|
|
||
| /// API version supported by the Level Zero driver. | ||
| ze_api_version_t APIVersion = ZE_API_VERSION_CURRENT; | ||
|
|
||
| /// Imported external pointers. Track this only for user-directed | ||
| /// imports/releases. | ||
| llvm::DenseMap<uintptr_t, size_t> ImportedPtrs; | ||
|
|
||
| /// Common event pool. | ||
| EventPoolTy EventPool; | ||
|
|
||
| /// Host Memory allocator for this driver. | ||
| MemAllocatorTy HostMemAllocator; | ||
|
|
||
| public: | ||
| /// Named constants for checking the imported external pointer regions. | ||
| static constexpr int32_t ImportNotExist = -1; | ||
| static constexpr int32_t ImportUnknown = 0; | ||
| static constexpr int32_t ImportExist = 1; | ||
|
|
||
| /// Create context, initialize event pool and extension functions. | ||
| L0ContextTy(LevelZeroPluginTy &Plugin, ze_driver_handle_t zeDriver, | ||
| int32_t DriverId) | ||
| : Plugin(Plugin), zeDriver(zeDriver) {} | ||
|
|
||
| L0ContextTy(const L0ContextTy &) = delete; | ||
| L0ContextTy(L0ContextTy &&) = delete; | ||
| L0ContextTy &operator=(const L0ContextTy &) = delete; | ||
| L0ContextTy &operator=(const L0ContextTy &&) = delete; | ||
|
|
||
| /// Release resources. | ||
| ~L0ContextTy() = default; | ||
|
|
||
| Error init(); | ||
| Error deinit(); | ||
|
|
||
| LevelZeroPluginTy &getPlugin() const { return Plugin; } | ||
|
|
||
| StagingBufferTy &getStagingBuffer(); | ||
|
|
||
| /// Add imported external pointer region. | ||
| void addImported(void *Ptr, size_t Size) { | ||
| (void)ImportedPtrs.try_emplace(reinterpret_cast<uintptr_t>(Ptr), Size); | ||
| } | ||
|
|
||
| /// Remove imported external pointer region. | ||
| void removeImported(void *Ptr) { | ||
| (void)ImportedPtrs.erase(reinterpret_cast<uintptr_t>(Ptr)); | ||
| } | ||
| /// Check if imported regions contain the specified region. | ||
| int32_t checkImported(void *Ptr, size_t Size) const { | ||
| uintptr_t LB = reinterpret_cast<uintptr_t>(Ptr); | ||
| uintptr_t UB = LB + Size; | ||
| // We do not expect a large number of user-directed imports, so use simple | ||
| // logic. | ||
| for (auto &I : ImportedPtrs) { | ||
| uintptr_t ILB = I.first; | ||
| uintptr_t IUB = ILB + I.second; | ||
| if (LB >= ILB && UB <= IUB) | ||
| return ImportExist; | ||
| if ((LB >= ILB && LB < IUB) || (UB > ILB && UB <= IUB)) | ||
| return ImportUnknown; | ||
| } | ||
| return ImportNotExist; | ||
| } | ||
|
|
||
| ze_driver_handle_t getZeDriver() const { return zeDriver; } | ||
|
|
||
| /// Return context associated with the driver. | ||
| ze_context_handle_t getZeContext() const { return zeContext; } | ||
|
|
||
| /// Return driver API version. | ||
| ze_api_version_t getDriverAPIVersion() const { return APIVersion; } | ||
|
|
||
| /// Return the event pool of this driver. | ||
| EventPoolTy &getEventPool() { return EventPool; } | ||
| const EventPoolTy &getEventPool() const { return EventPool; } | ||
|
|
||
| bool supportsLargeMem() const { | ||
| // Large memory support is available since API version 1.1. | ||
| return getDriverAPIVersion() >= ZE_API_VERSION_1_1; | ||
| } | ||
|
|
||
| const MemAllocatorTy &getHostMemAllocator() const { return HostMemAllocator; } | ||
| MemAllocatorTy &getHostMemAllocator() { return HostMemAllocator; } | ||
| }; | ||
|
|
||
| } // namespace llvm::omp::target::plugin | ||
|
|
||
| #endif // OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_LEVEL_ZERO_L0CONTEXT_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.