-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc] Ignore 'errno' on the GPU and support 'atoi'
The 'errno' value is most likely not useful on the GPU and it prevents us from providing certain functions on the GPU that depend on it, like `atoi`. This patch makes the necessary changes to support `errno` by simple replacing it with a consumer class. Supporting `errno` on the GPU is possible in some aspects. The first approach would be to use a buffer of shared memory that has enough space for all threads. Another option would be to change code generation to support `thread_local` using `address_space(5)` memory allocated at kernel launch. The former could look like the following, which could be implemented in a later patch: ``` template <typename T> using SharedBuffer = T[gpu::MAX_THREADS] [[clang::address_space(3)]]; template <typename T> struct ErrnoSetter { constexpr ErrnoSetter(SharedBuffer<T> &storage) : storage(storage) {} SharedBuffer<T> &storage; void operator=(const T &val) { storage[gpu::get_thread_id()] = val; } }; static SharedBuffer<int> thread_local_buffer [[clang::loader_uninitialized]]; ErrnoSetter<int> __llvmlibc_internal_errno(thread_local_buffer); ``` Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149107
- Loading branch information
Showing
5 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
set(TARGET_PUBLIC_HEADERS | ||
libc.include.ctype | ||
libc.include.string | ||
libc.include.stdlib | ||
) |
This file contains 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 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 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