27
27
#endif
28
28
#include < cstring>
29
29
30
- #define UNUSED GGML_UNUSED
31
-
32
- #define GGML_DEBUG 0
33
- #if (GGML_DEBUG >= 1)
34
- #define GGML_PRINT_DEBUG (...) printf(__VA_ARGS__)
35
- #else
36
- #define GGML_PRINT_DEBUG (...)
37
- #endif
38
-
39
30
#ifdef _WIN32
40
31
typedef SOCKET sockfd_t ;
41
32
using ssize_t = __int64;
@@ -411,7 +402,7 @@ static std::shared_ptr<socket_t> get_socket(const std::string & endpoint) {
411
402
initialized = true ;
412
403
}
413
404
#else
414
- UNUSED (initialized);
405
+ GGML_UNUSED (initialized);
415
406
#endif
416
407
auto sock = socket_connect (host.c_str (), port);
417
408
if (sock == nullptr ) {
@@ -640,7 +631,7 @@ static void ggml_backend_rpc_free(ggml_backend_t backend) {
640
631
}
641
632
642
633
static void ggml_backend_rpc_synchronize (ggml_backend_t backend) {
643
- UNUSED (backend);
634
+ GGML_UNUSED (backend);
644
635
// this is no-op because we don't have any async operations
645
636
}
646
637
@@ -850,7 +841,7 @@ void rpc_server::alloc_buffer(const rpc_msg_alloc_buffer_req & request, rpc_msg_
850
841
GGML_PRINT_DEBUG (" [%s] size: %" PRIu64 " -> remote_ptr: %" PRIx64 " , remote_size: %" PRIu64 " \n " , __func__, request.size , response.remote_ptr , response.remote_size );
851
842
buffers.insert (buffer);
852
843
} else {
853
- GGML_PRINT_DEBUG (" [%s] size: %" PRIu64 " -> failed\n " , __func__, request.size );
844
+ GGML_LOG_ERROR (" [%s] size: %" PRIu64 " -> failed\n " , __func__, request.size );
854
845
}
855
846
}
856
847
@@ -872,7 +863,7 @@ bool rpc_server::buffer_get_base(const rpc_msg_buffer_get_base_req & request, rp
872
863
GGML_PRINT_DEBUG (" [%s] remote_ptr: %" PRIx64 " \n " , __func__, request.remote_ptr );
873
864
ggml_backend_buffer_t buffer = reinterpret_cast <ggml_backend_buffer_t >(request.remote_ptr );
874
865
if (buffers.find (buffer) == buffers.end ()) {
875
- GGML_PRINT_DEBUG (" [%s] buffer not found\n " , __func__);
866
+ GGML_LOG_ERROR (" [%s] buffer not found\n " , __func__);
876
867
return false ;
877
868
}
878
869
void * base = ggml_backend_buffer_get_base (buffer);
@@ -884,7 +875,7 @@ bool rpc_server::free_buffer(const rpc_msg_free_buffer_req & request) {
884
875
GGML_PRINT_DEBUG (" [%s] remote_ptr: %" PRIx64 " \n " , __func__, request.remote_ptr );
885
876
ggml_backend_buffer_t buffer = reinterpret_cast <ggml_backend_buffer_t >(request.remote_ptr );
886
877
if (buffers.find (buffer) == buffers.end ()) {
887
- GGML_PRINT_DEBUG (" [%s] buffer not found\n " , __func__);
878
+ GGML_LOG_ERROR (" [%s] buffer not found\n " , __func__);
888
879
return false ;
889
880
}
890
881
ggml_backend_buffer_free (buffer);
@@ -896,7 +887,7 @@ bool rpc_server::buffer_clear(const rpc_msg_buffer_clear_req & request) {
896
887
GGML_PRINT_DEBUG (" [%s] remote_ptr: %" PRIx64 " , value: %u\n " , __func__, request.remote_ptr , request.value );
897
888
ggml_backend_buffer_t buffer = reinterpret_cast <ggml_backend_buffer_t >(request.remote_ptr );
898
889
if (buffers.find (buffer) == buffers.end ()) {
899
- GGML_PRINT_DEBUG (" [%s] buffer not found\n " , __func__);
890
+ GGML_LOG_ERROR (" [%s] buffer not found\n " , __func__);
900
891
return false ;
901
892
}
902
893
ggml_backend_buffer_clear (buffer, request.value );
@@ -952,7 +943,7 @@ bool rpc_server::set_tensor(const std::vector<uint8_t> & input) {
952
943
struct ggml_context * ctx = ggml_init (params);
953
944
ggml_tensor * tensor = deserialize_tensor (ctx, in_tensor);
954
945
if (tensor == nullptr ) {
955
- GGML_PRINT_DEBUG (" [%s] error deserializing tensor\n " , __func__);
946
+ GGML_LOG_ERROR (" [%s] error deserializing tensor\n " , __func__);
956
947
ggml_free (ctx);
957
948
return false ;
958
949
}
@@ -1017,7 +1008,7 @@ bool rpc_server::get_tensor(const rpc_msg_get_tensor_req & request, std::vector<
1017
1008
struct ggml_context * ctx = ggml_init (params);
1018
1009
ggml_tensor * tensor = deserialize_tensor (ctx, &request.tensor );
1019
1010
if (tensor == nullptr ) {
1020
- GGML_PRINT_DEBUG (" [%s] error deserializing tensor\n " , __func__);
1011
+ GGML_LOG_ERROR (" [%s] error deserializing tensor\n " , __func__);
1021
1012
ggml_free (ctx);
1022
1013
return false ;
1023
1014
}
@@ -1051,7 +1042,7 @@ bool rpc_server::copy_tensor(const rpc_msg_copy_tensor_req & request, rpc_msg_co
1051
1042
ggml_tensor * src = deserialize_tensor(ctx, &request.src);
1052
1043
ggml_tensor * dst = deserialize_tensor(ctx, &request.dst);
1053
1044
if (src == nullptr || dst == nullptr ) {
1054
- GGML_PRINT_DEBUG (" [%s] error deserializing tensors\n " , __func__);
1045
+ GGML_LOG_ERROR (" [%s] error deserializing tensors\n " , __func__);
1055
1046
ggml_free (ctx);
1056
1047
return false ;
1057
1048
}
@@ -1385,14 +1376,14 @@ static void ggml_backend_rpc_device_get_memory(ggml_backend_dev_t dev, size_t *
1385
1376
1386
1377
ggml_backend_rpc_get_device_memory (ctx->endpoint .c_str (), free, total);
1387
1378
1388
- UNUSED (dev);
1379
+ GGML_UNUSED (dev);
1389
1380
}
1390
1381
1391
1382
static enum ggml_backend_dev_type ggml_backend_rpc_device_get_type (ggml_backend_dev_t dev) {
1392
1383
// TODO: obtain value from the server
1393
1384
return GGML_BACKEND_DEVICE_TYPE_GPU;
1394
1385
1395
- UNUSED (dev);
1386
+ GGML_UNUSED (dev);
1396
1387
}
1397
1388
1398
1389
static void ggml_backend_rpc_device_get_props (ggml_backend_dev_t dev, struct ggml_backend_dev_props * props) {
@@ -1413,20 +1404,20 @@ static ggml_backend_t ggml_backend_rpc_device_init(ggml_backend_dev_t dev, const
1413
1404
1414
1405
return ggml_backend_rpc_init (ctx->endpoint .c_str ());
1415
1406
1416
- UNUSED (params);
1407
+ GGML_UNUSED (params);
1417
1408
}
1418
1409
1419
1410
static ggml_backend_buffer_type_t ggml_backend_rpc_device_get_buffer_type (ggml_backend_dev_t dev) {
1420
1411
ggml_backend_rpc_device_context * ctx = (ggml_backend_rpc_device_context *)dev->context ;
1421
1412
1422
1413
return ggml_backend_rpc_buffer_type (ctx->endpoint .c_str ());
1423
1414
1424
- UNUSED (dev);
1415
+ GGML_UNUSED (dev);
1425
1416
}
1426
1417
1427
1418
static bool ggml_backend_rpc_device_supports_op (ggml_backend_dev_t dev, const struct ggml_tensor * op) {
1428
- UNUSED (dev);
1429
- UNUSED (op);
1419
+ GGML_UNUSED (dev);
1420
+ GGML_UNUSED (op);
1430
1421
// TODO: call the remote backend and cache the results
1431
1422
return true ;
1432
1423
}
@@ -1463,20 +1454,20 @@ static const struct ggml_backend_device_i ggml_backend_rpc_device_i = {
1463
1454
static const char * ggml_backend_rpc_reg_get_name (ggml_backend_reg_t reg) {
1464
1455
return " RPC" ;
1465
1456
1466
- UNUSED (reg);
1457
+ GGML_UNUSED (reg);
1467
1458
}
1468
1459
1469
1460
static size_t ggml_backend_rpc_reg_get_device_count (ggml_backend_reg_t reg) {
1470
1461
return 0 ;
1471
1462
1472
- UNUSED (reg);
1463
+ GGML_UNUSED (reg);
1473
1464
}
1474
1465
1475
1466
static ggml_backend_dev_t ggml_backend_rpc_reg_get_device (ggml_backend_reg_t reg, size_t index) {
1476
1467
GGML_ABORT (" The RPC backend does not have enumerated devices - use ggml_backend_add_device instead" );
1477
1468
1478
- UNUSED (reg);
1479
- UNUSED (index);
1469
+ GGML_UNUSED (reg);
1470
+ GGML_UNUSED (index);
1480
1471
}
1481
1472
1482
1473
static void * ggml_backend_rpc_get_proc_address (ggml_backend_reg_t reg, const char * name) {
@@ -1485,7 +1476,7 @@ static void * ggml_backend_rpc_get_proc_address(ggml_backend_reg_t reg, const ch
1485
1476
}
1486
1477
return NULL ;
1487
1478
1488
- UNUSED (reg);
1479
+ GGML_UNUSED (reg);
1489
1480
}
1490
1481
1491
1482
static const struct ggml_backend_reg_i ggml_backend_rpc_reg_i = {
0 commit comments