diff options
author | Georgi Gerganov <ggerganov@gmail.com> | 2024-06-17 11:09:20 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-17 11:09:20 +0300 |
commit | 21be9cab94e0b5b53cb6edeeebf8c8c799baad03 (patch) | |
tree | 32bdd95493f1a1ff03c728ab1753da96f2874a05 | |
parent | 006167aaf6b6aaa4daa52961035f7460af19f469 (diff) |
rpc : fix load/store misaligned addresses (#7948)
-rw-r--r-- | ggml-rpc.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/ggml-rpc.cpp b/ggml-rpc.cpp index 22d9524b..b01ad267 100644 --- a/ggml-rpc.cpp +++ b/ggml-rpc.cpp @@ -73,9 +73,13 @@ struct rpc_tensor { uint64_t view_offs; uint64_t data; char name[GGML_MAX_NAME]; + + char padding[4]; }; #pragma pack(pop) +static_assert(sizeof(rpc_tensor) % 8 == 0, "rpc_tensor size must be multiple of 8"); + // RPC commands enum rpc_cmd { ALLOC_BUFFER = 0, @@ -599,9 +603,8 @@ static void serialize_graph(const ggml_cgraph * cgraph, std::vector<uint8_t> & o int output_size = sizeof(uint32_t) + n_nodes * sizeof(uint64_t) + sizeof(uint32_t) + n_tensors * sizeof(rpc_tensor); output.resize(output_size, 0); memcpy(output.data(), &n_nodes, sizeof(n_nodes)); - uint64_t * out_nodes = (uint64_t *)(output.data() + sizeof(n_nodes)); for (uint32_t i = 0; i < n_nodes; i++) { - out_nodes[i] = reinterpret_cast<uint64_t>(cgraph->nodes[i]); + memcpy(output.data() + sizeof(n_nodes) + i * sizeof(uint64_t), &cgraph->nodes[i], sizeof(uint64_t)); } uint32_t * out_ntensors = (uint32_t *)(output.data() + sizeof(n_nodes) + n_nodes * sizeof(uint64_t)); *out_ntensors = n_tensors; @@ -1036,7 +1039,9 @@ bool rpc_server::graph_compute(const std::vector<uint8_t> & input, std::vector<u } std::unordered_map<uint64_t, ggml_tensor*> tensor_map; for (uint32_t i = 0; i < n_nodes; i++) { - graph->nodes[i] = create_node(nodes[i], ctx, tensor_ptrs, tensor_map); + int64_t id; + memcpy(&id, &nodes[i], sizeof(id)); + graph->nodes[i] = create_node(id, ctx, tensor_ptrs, tensor_map); } ggml_status status = ggml_backend_graph_compute(backend, graph); // output serialization format: | status (1 byte) | |