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
52 lines
1.1 KiB
Modula-2
52 lines
1.1 KiB
Modula-2
//===-- C standard library header errno.h ---------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_LIBC_ERRNO_H
|
|
#define LLVM_LIBC_ERRNO_H
|
|
|
|
#include <__llvm-libc-common.h>
|
|
|
|
#ifdef __linux__
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#ifndef ERFKILL
|
|
#define ERFKILL 132
|
|
#endif // ERFKILL
|
|
|
|
#ifndef EOWNERDEAD
|
|
#define EOWNERDEAD 130
|
|
#endif // EOWNERDEAD
|
|
|
|
#ifndef EHWPOISON
|
|
#define EHWPOISON 133
|
|
#endif // EHWPOISON
|
|
|
|
#ifndef ECANCELED
|
|
#define ECANCELED 125
|
|
#endif // ECANCELED
|
|
|
|
#ifndef ENOTSUP
|
|
#define ENOTSUP EOPNOTSUPP
|
|
#endif // ENOTSUP
|
|
|
|
#ifndef ENOTRECOVERABLE
|
|
#define ENOTRECOVERABLE 131
|
|
#endif // ENOTRECOVERABLE
|
|
|
|
#else // __linux__
|
|
#include <llvm-libc-macros/generic-error-number-macros.h>
|
|
#endif
|
|
|
|
#if !defined(__AMDGPU__) && !defined(__NVPTX__)
|
|
extern _Thread_local int __llvmlibc_errno;
|
|
#define errno __llvmlibc_errno
|
|
#endif
|
|
|
|
#endif // LLVM_LIBC_ERRNO_H
|