| #ifndef DS4_TP_H |
| #define DS4_TP_H |
|
|
| #include <stdbool.h> |
| #include <stddef.h> |
| #include <stdint.h> |
| #include <stdio.h> |
|
|
| #include "ds4.h" |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| typedef struct ds4_tp ds4_tp; |
|
|
| enum { |
| DS4_TP_GATE_ATTN = 0, |
| DS4_TP_GATE_FFN = 1, |
| DS4_TP_GATES_PER_LAYER = 2, |
| |
| DS4_TP_BATCH_MAX_ROWS = 8, |
| }; |
|
|
| |
| |
| typedef struct { |
| uint64_t gguf_bytes; |
| uint32_t model_id; |
| uint32_t n_layer; |
| uint32_t n_embd; |
| uint32_t n_vocab; |
| uint32_t quant_bits; |
| uint32_t ctx_size; |
| |
| |
| |
| |
| |
| |
| uint32_t gate_slot_start; |
| uint32_t gate_slot_step; |
| uint32_t gates_per_token; |
| } ds4_tp_identity; |
|
|
| bool ds4_tp_enabled(const ds4_tp_options *opt); |
|
|
| typedef enum { |
| DS4_TP_CLI_ERROR = -1, |
| DS4_TP_CLI_NOT_MATCHED = 0, |
| DS4_TP_CLI_MATCHED = 1, |
| } ds4_tp_cli_parse_result; |
|
|
| |
| |
| int ds4_tp_parse_cli_arg( |
| const char *arg, |
| int *index, |
| int argc, |
| char **argv, |
| ds4_tp_options *opt, |
| char *err, |
| size_t errlen); |
| int ds4_tp_adopt_distributed_options( |
| ds4_tp_options *tp, |
| ds4_distributed_options *dist, |
| char *err, |
| size_t errlen); |
| void ds4_tp_usage(FILE *fp); |
|
|
| |
| |
| int ds4_tp_validate_engine_options( |
| const ds4_engine_options *opt, |
| char *err, |
| size_t errlen); |
|
|
| |
| |
| |
| int ds4_tp_create( |
| ds4_tp **out, |
| const ds4_tp_options *opt, |
| const ds4_tp_identity *id, |
| char *err, |
| size_t errlen); |
| void ds4_tp_free(ds4_tp *tp); |
|
|
| int ds4_tp_rank(const ds4_tp *tp); |
| bool ds4_tp_is_rdma(const ds4_tp *tp); |
| uint32_t ds4_tp_peer_ctx(const ds4_tp *tp); |
| bool ds4_tp_failed(const ds4_tp *tp); |
| void ds4_tp_mark_failed(ds4_tp *tp); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| uint64_t ds4_tp_slab_bytes(uint32_t n_layer, uint32_t n_embd); |
| uint64_t ds4_tp_slab_out_offset(const ds4_tp *tp, uint32_t layer, uint32_t gate); |
| uint64_t ds4_tp_slab_in_offset(const ds4_tp *tp, uint32_t layer, uint32_t gate); |
| uint64_t ds4_tp_slab_batch_out_offset(const ds4_tp *tp, uint32_t layer); |
| uint64_t ds4_tp_slab_batch_in_offset(const ds4_tp *tp, uint32_t layer); |
| uint64_t ds4_tp_slab_gpu_flags_offset(const ds4_tp *tp); |
| int ds4_tp_attach_slab(ds4_tp *tp, void *base, char *err, size_t errlen); |
|
|
| |
| |
| |
| int ds4_tp_gate_exchange(ds4_tp *tp, uint32_t layer, uint32_t gate, uint64_t seq); |
|
|
| |
| |
| |
| int ds4_tp_batch_gate_exchange(ds4_tp *tp, uint32_t layer, uint32_t rows, |
| uint64_t seq); |
|
|
| |
| |
| int ds4_tp_big_gate_exchange(ds4_tp *tp, uint32_t layer, uint64_t seq, |
| const void *out, void *in, uint64_t bytes); |
|
|
| |
| typedef struct { |
| uint64_t session_id; |
| int32_t token; |
| uint32_t reserved; |
| } ds4_tp_batch_item; |
|
|
| int ds4_tp_send_session_create(ds4_tp *tp, uint64_t session_id, int ctx_size); |
| int ds4_tp_send_session_destroy(ds4_tp *tp, uint64_t session_id); |
| int ds4_tp_send_sync(ds4_tp *tp, uint64_t session_id, |
| const int *tokens, uint32_t n_tokens); |
| int ds4_tp_send_eval(ds4_tp *tp, uint64_t session_id, |
| uint64_t seq, int token); |
| int ds4_tp_send_rewind(ds4_tp *tp, uint64_t session_id, int pos); |
| int ds4_tp_send_invalidate(ds4_tp *tp, uint64_t session_id); |
| int ds4_tp_send_eval_batch(ds4_tp *tp, const ds4_tp_batch_item *items, |
| uint32_t count); |
| int ds4_tp_send_mixed_batch(ds4_tp *tp, uint64_t prefill_session_id, |
| const int *prompt, uint32_t prompt_count, |
| const ds4_tp_batch_item *items, |
| uint32_t count); |
| int ds4_tp_send_command_ack(ds4_tp *tp, uint64_t session_id, int status); |
| int ds4_tp_wait_command_ack(ds4_tp *tp, uint64_t session_id, |
| const char *operation, char *err, size_t errlen); |
| int ds4_tp_send_stop(ds4_tp *tp); |
|
|
| |
| |
| |
| typedef enum { |
| DS4_TP_FRAME_ERROR = -1, |
| DS4_TP_FRAME_SYNC = 1, |
| DS4_TP_FRAME_EVAL = 2, |
| DS4_TP_FRAME_REWIND = 3, |
| DS4_TP_FRAME_INVALIDATE = 4, |
| DS4_TP_FRAME_STOP = 5, |
| DS4_TP_FRAME_HASH = 6, |
| DS4_TP_FRAME_RDMA_INFO = 7, |
| DS4_TP_FRAME_SYNC_ACK = 8, |
| DS4_TP_FRAME_RDMA_READY = 9, |
| DS4_TP_FRAME_LOGITS = 10, |
| DS4_TP_FRAME_VERIFY = 11, |
| DS4_TP_FRAME_VERIFY_COMMIT = 12, |
| DS4_TP_FRAME_SESSION_CREATE = 13, |
| DS4_TP_FRAME_SESSION_DESTROY = 14, |
| DS4_TP_FRAME_EVAL_BATCH = 15, |
| DS4_TP_FRAME_MIXED_BATCH = 16, |
| DS4_TP_FRAME_COMMAND_ACK = 17, |
| } ds4_tp_frame_type; |
|
|
| typedef struct { |
| ds4_tp_frame_type type; |
| uint64_t session_id; |
| uint64_t seq; |
| int value; |
| int *tokens; |
| uint32_t n_tokens; |
| ds4_tp_batch_item *items; |
| uint32_t n_items; |
| } ds4_tp_command; |
|
|
| int ds4_tp_recv_command( |
| ds4_tp *tp, |
| ds4_tp_command *command, |
| char *err, |
| size_t errlen); |
| void ds4_tp_command_free(ds4_tp_command *command); |
|
|
| |
| |
| int ds4_tp_hash_check(ds4_tp *tp, uint64_t seq, uint64_t hash, char *err, size_t errlen); |
|
|
| |
| |
| int ds4_tp_send_logits_half(ds4_tp *tp, const float *half, uint32_t count); |
| int ds4_tp_recv_logits_half(ds4_tp *tp, float *half, uint32_t count); |
|
|
| |
| |
| |
| |
| |
| int ds4_tp_send_verify(ds4_tp *tp, uint64_t session_id, |
| const int *drafts, uint32_t n); |
| int ds4_tp_send_verify_commit(ds4_tp *tp, int32_t full_accept, int32_t replay_n); |
| int ds4_tp_recv_verify_commit(ds4_tp *tp, int32_t *full_accept, int32_t *replay_n); |
|
|
| |
| |
| int ds4_tp_worker_run(ds4_engine *engine, const ds4_tp_options *opt); |
|
|
| #endif |
|
|