diff --git a/libc/config/gpu/api.td b/libc/config/gpu/api.td --- a/libc/config/gpu/api.td +++ b/libc/config/gpu/api.td @@ -1,6 +1,7 @@ include "config/public_api.td" include "spec/stdc.td" +include "spec/gpu_ext.td" def StringAPI : PublicAPI<"string.h"> { let Types = ["size_t"]; diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/entrypoints.txt @@ -79,6 +79,9 @@ libc.src.stdio.stdin libc.src.stdio.stdout libc.src.stdio.stderr + + # gpu/rpc.h entrypoints + libc.src.gpu.rpc_reset ) set(TARGET_LLVMLIBC_ENTRYPOINTS diff --git a/libc/config/gpu/headers.txt b/libc/config/gpu/headers.txt --- a/libc/config/gpu/headers.txt +++ b/libc/config/gpu/headers.txt @@ -5,4 +5,7 @@ libc.include.errno libc.include.stdlib libc.include.stdio + + # Header for RPC extensions + libc.include.gpu_rpc ) diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt --- a/libc/include/CMakeLists.txt +++ b/libc/include/CMakeLists.txt @@ -487,6 +487,18 @@ .llvm-libc-types.wchar_t ) +if(LIBC_TARGET_ARCHITECTURE_IS_GPU) +file(MAKE_DIRECTORY "gpu") + +add_gen_header( + gpu_rpc + DEF_FILE gpu/rpc.h.def + GEN_HDR gpu/rpc.h + DEPENDS + .llvm_libc_common_h +) +endif() + if(NOT LLVM_LIBC_FULL_BUILD) # We don't install headers in non-fullbuild mode. return() diff --git a/libc/include/gpu/rpc.h.def b/libc/include/gpu/rpc.h.def new file mode 100644 --- /dev/null +++ b/libc/include/gpu/rpc.h.def @@ -0,0 +1,16 @@ +//===-- GPO header rpc.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_GPU_RPC_H +#define LLVM_LIBC_GPU_RPC_H + +#include <__llvm-libc-common.h> + +%%public_api() + +#endif // LLVM_LIBC_GPU_RPC_H diff --git a/libc/spec/gpu_ext.td b/libc/spec/gpu_ext.td new file mode 100644 --- /dev/null +++ b/libc/spec/gpu_ext.td @@ -0,0 +1,18 @@ +def GPUExtensions : StandardSpec<"GPUExtensions"> { + HeaderSpec RPC = HeaderSpec< + "gpu/rpc.h", + [], // Macros + [], // Types + [], // Enumerations + [ + FunctionSpec< + "rpc_reset", + RetValSpec, + [ArgSpec, ArgSpec] + >, + ] + >; + let Headers = [ + RPC, + ]; +} diff --git a/libc/src/CMakeLists.txt b/libc/src/CMakeLists.txt --- a/libc/src/CMakeLists.txt +++ b/libc/src/CMakeLists.txt @@ -20,6 +20,10 @@ add_subdirectory(unistd) endif() +if(${LIBC_TARGET_OS} STREQUAL "gpu") + add_subdirectory(gpu) +endif() + if(NOT LLVM_LIBC_FULL_BUILD) return() endif() diff --git a/libc/src/gpu/CMakeLists.txt b/libc/src/gpu/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/libc/src/gpu/CMakeLists.txt @@ -0,0 +1,10 @@ +add_entrypoint_object( + rpc_reset + SRCS + rpc_reset.cpp + HDRS + rpc_reset.h + DEPENDS + libc.src.__support.RPC.rpc_client + libc.src.__support.GPU.utils +) diff --git a/libc/src/gpu/rpc_reset.h b/libc/src/gpu/rpc_reset.h new file mode 100644 --- /dev/null +++ b/libc/src/gpu/rpc_reset.h @@ -0,0 +1,18 @@ +//===-- Implementation header for RPC functions -----------------*- C++ -*-===// +// +// 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_SRC_GPU_RPC_H +#define LLVM_LIBC_SRC_GPU_RPC_H + +namespace __llvm_libc { + +void rpc_reset(unsigned int num_ports, void *buffer); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_GPU_RPC_H diff --git a/libc/src/gpu/rpc_reset.cpp b/libc/src/gpu/rpc_reset.cpp new file mode 100644 --- /dev/null +++ b/libc/src/gpu/rpc_reset.cpp @@ -0,0 +1,25 @@ +//===---------- GPU implementation of the external RPC functionion --------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "src/gpu/rpc_reset.h" + +#include "src/__support/GPU/utils.h" +#include "src/__support/RPC/rpc_client.h" +#include "src/__support/common.h" + +namespace __llvm_libc { + +// This is the external interface to initialize the RPC client with the +// shared buffer. +LLVM_LIBC_FUNCTION(void, rpc_reset, + (unsigned int num_ports, void *rpc_shared_buffer)) { + __llvm_libc::rpc::client.reset(num_ports, __llvm_libc::gpu::get_lane_size(), + rpc_shared_buffer); +} + +} // namespace __llvm_libc