Skip to content

Commit e397396

Browse files
authored
Merge pull request #4 from kpouget/remoting
Remoting: add the remoting backend skeleton code
2 parents d8d3c8e + 78d16d0 commit e397396

18 files changed

+232
-52
lines changed

CMakePresets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
{ "name": "sycl_f16", "hidden": true, "cacheVariables": { "GGML_SYCL_F16": "ON" } },
3232
{ "name": "vulkan", "hidden": true, "cacheVariables": { "GGML_VULKAN": "ON" } },
3333
{ "name": "remoting_frontend", "hidden": true, "cacheVariables": { "GGML_REMOTING_FRONTEND": "ON" } },
34+
{ "name": "remoting_backend", "hidden": true, "cacheVariables": { "GGML_REMOTING_BACKEND": "ON" } },
3435

3536
{
3637
"name": "x64-windows-llvm", "hidden": true,

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,11 @@ ifdef GGML_REMOTING_FRONTEND
721721
OBJ_GGML_EXT += ggml/src/ggml-remotingfrontend/ggml-remoting-frontend.o
722722
endif
723723

724+
ifdef GGML_REMOTING_BACKEND
725+
MK_CPPFLAGS += -DGGML_USE_REMOTINGBACKEND
726+
OBJ_GGML_EXT += ggml/src/ggml-remotingbackend/ggml-remoting-backend.o
727+
endif
728+
724729
ifdef GGML_VULKAN
725730
MK_CPPFLAGS += -DGGML_USE_VULKAN
726731
MK_LDFLAGS += $(shell pkg-config --libs vulkan)
@@ -763,6 +768,9 @@ ggml/src/ggml-vulkan.o: ggml/src/ggml-vulkan/ggml-vulkan.cpp ggml/include/ggml-v
763768
ggml/src/ggml-remotingfrontend/frontend.o: ggml/src/ggml-remotingfrontend/frontend.cpp
764769
$(CXX) $(CXXFLAGS) -c $< -o $@
765770

771+
ggml/src/ggml-remotingbackend/backend.o: ggml/src/ggml-remotingbackend/backend.cpp
772+
$(CXX) $(CXXFLAGS) -c $< -o $@
773+
766774
$(_ggml_vk_header): $(_ggml_vk_source)
767775

768776
$(_ggml_vk_source): $(_ggml_vk_shader_deps) vulkan-shaders-gen

build.backend.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# force isatty-->true, so that $0 |& head -50 has colors ...
2+
rm -f READY_backend FAILED_backend
3+
4+
echo "int isatty(int fd) { return 1; }" | gcc -O2 -fpic -shared -ldl -o /tmp/isatty.so -xc -
5+
export LD_PRELOAD=/tmp/isatty.so
6+
7+
cmake --build ../build.remoting-backend --parallel 8 --target llama-cli "$@"
8+
9+
if [[ $? == 0 ]]; then
10+
touch READY_backend
11+
else
12+
touch FAILED_backend
13+
fi

ggml/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ option(GGML_VULKAN_PERF "ggml: enable Vulkan perf output"
180180
option(GGML_VULKAN_VALIDATE "ggml: enable Vulkan validation" OFF)
181181
option(GGML_VULKAN_RUN_TESTS "ggml: run Vulkan tests" OFF)
182182
option(GGML_REMOTING_FRONTEND "ggml: use the API Remoting frontend" OFF)
183+
option(GGML_REMOTING_BACKEND "ggml: use the API Remoting backend" OFF)
183184
option(GGML_KOMPUTE "ggml: use Kompute" OFF)
184185
option(GGML_METAL "ggml: use Metal" ${GGML_METAL_DEFAULT})
185186
option(GGML_METAL_USE_BF16 "ggml: use bfloat if available" OFF)
@@ -270,7 +271,8 @@ set(GGML_PUBLIC_HEADERS
270271
include/ggml-rpc.h
271272
include/ggml-sycl.h
272273
include/ggml-vulkan.h
273-
include/ggml-remoting-frontend.h
274+
ggml/include/ggml-remoting-frontend.h
275+
ggml/include/ggml-remoting-backend.h
274276
include/gguf.h)
275277

276278
set_target_properties(ggml PROPERTIES PUBLIC_HEADER "${GGML_PUBLIC_HEADERS}")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include "ggml.h"
4+
#include "ggml-backend.h"
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
#define GGML_REMOTING_BACKEND_NAME "RemotingBackend"
11+
12+
GGML_BACKEND_API ggml_backend_reg_t ggml_backend_remoting_backend_reg();
13+
14+
#ifdef __cplusplus
15+
}
16+
#endif

ggml/include/ggml-remoting-frontend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
extern "C" {
88
#endif
99

10-
#define GGML_REMOTING_NAME "RemotingFrontend"
10+
#define GGML_REMOTING_FRONTEND_NAME "RemotingFrontend"
1111

12-
GGML_BACKEND_API ggml_backend_reg_t ggml_backend_remoting_reg();
12+
GGML_BACKEND_API ggml_backend_reg_t ggml_backend_remoting_frontend_reg();
1313

1414
#ifdef __cplusplus
1515
}

ggml/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ ggml_add_backend(RPC)
310310
ggml_add_backend(SYCL)
311311
ggml_add_backend(Vulkan)
312312
ggml_add_backend(RemotingFrontend)
313+
ggml_add_backend(RemotingBackend)
313314
ggml_add_backend(OpenCL)
314315

315316
foreach (target ggml-base ggml)

ggml/src/ggml-backend-reg.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
#include "ggml-remoting-frontend.h"
5050
#endif
5151

52+
#ifdef GGML_USE_REMOTINGBACKEND
53+
#include "ggml-remoting-backend.h"
54+
#endif
55+
5256
#ifdef GGML_USE_OPENCL
5357
#include "ggml-opencl.h"
5458
#endif
@@ -177,7 +181,10 @@ struct ggml_backend_registry {
177181
register_backend(ggml_backend_vk_reg());
178182
#endif
179183
#ifdef GGML_USE_REMOTINGFRONTEND
180-
register_backend(ggml_backend_remoting_reg());
184+
register_backend(ggml_backend_remoting_frontend_reg());
185+
#endif
186+
#ifdef GGML_USE_REMOTINGBACKEND
187+
register_backend(ggml_backend_remoting_backend_reg());
181188
#endif
182189
#ifdef GGML_USE_OPENCL
183190
register_backend(ggml_backend_opencl_reg());
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.19)
2+
cmake_policy(SET CMP0114 NEW)
3+
4+
message(STATUS "Enable API Remoting backend")
5+
6+
ggml_add_backend_library(ggml-remotingbackend
7+
backend.cpp
8+
../../include/ggml-remoting-backend.h
9+
)
10+
11+
target_compile_options(ggml-remotingbackend PRIVATE -std=c++20)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <cstdio>
2+
#include <cstdarg>
3+
4+
static inline void LOG(const char* fmt, ...) {
5+
va_list args;
6+
va_start(args, fmt);
7+
vprintf(fmt, args);
8+
va_end(args);
9+
10+
printf("\n");
11+
}
12+
13+
static inline void FATAL(const char* fmt, ...) {
14+
printf("FATAL: ");
15+
va_list args;
16+
va_start(args, fmt);
17+
vprintf(fmt, args);
18+
va_end(args);
19+
20+
printf("\n");
21+
22+
if (!fmt)
23+
return; // avoid the noreturn attribute
24+
25+
exit(1);
26+
}
27+
28+
extern "C" {
29+
void ggml_backend_remoting_backend_say_hello();
30+
}

0 commit comments

Comments
 (0)