ops.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. #include <torch/extension.h>
  3. void paged_attention_v1(
  4. torch::Tensor& out, torch::Tensor& query, torch::Tensor& key_cache,
  5. torch::Tensor& value_cache, int num_kv_heads, float scale,
  6. torch::Tensor& block_tables, torch::Tensor& seq_lens, int block_size,
  7. int max_seq_len, const c10::optional<torch::Tensor>& alibi_slopes,
  8. const std::string& kv_cache_dtype, float kv_scale, const int tp_rank,
  9. const int blocksparse_local_blocks, const int blocksparse_vert_stride,
  10. const int blocksparse_block_size, const int blocksparse_head_sliding_step);
  11. void paged_attention_v2(
  12. torch::Tensor& out, torch::Tensor& exp_sums, torch::Tensor& max_logits,
  13. torch::Tensor& tmp_out, torch::Tensor& query, torch::Tensor& key_cache,
  14. torch::Tensor& value_cache, int num_kv_heads, float scale,
  15. torch::Tensor& block_tables, torch::Tensor& seq_lens, int block_size,
  16. int max_seq_len, const c10::optional<torch::Tensor>& alibi_slopes,
  17. const std::string& kv_cache_dtype, float kv_scale, const int tp_rank,
  18. const int blocksparse_local_blocks, const int blocksparse_vert_stride,
  19. const int blocksparse_block_size, const int blocksparse_head_sliding_step);
  20. void rms_norm(torch::Tensor& out, torch::Tensor& input, torch::Tensor& weight,
  21. float epsilon);
  22. void fused_add_rms_norm(torch::Tensor& input, torch::Tensor& residual,
  23. torch::Tensor& weight, float epsilon);
  24. void rotary_embedding(torch::Tensor& positions, torch::Tensor& query,
  25. torch::Tensor& key, int head_size,
  26. torch::Tensor& cos_sin_cache, bool is_neox);
  27. void batched_rotary_embedding(torch::Tensor& positions, torch::Tensor& query,
  28. torch::Tensor& key, int head_size,
  29. torch::Tensor& cos_sin_cache, bool is_neox,
  30. int rot_dim,
  31. torch::Tensor& cos_sin_cache_offsets);
  32. void silu_and_mul(torch::Tensor& out, torch::Tensor& input);
  33. void gelu_and_mul(torch::Tensor& out, torch::Tensor& input);
  34. void gelu_tanh_and_mul(torch::Tensor& out, torch::Tensor& input);
  35. void gelu_new(torch::Tensor& out, torch::Tensor& input);
  36. void gelu_fast(torch::Tensor& out, torch::Tensor& input);
  37. void moe_align_block_size(torch::Tensor topk_ids, int num_experts,
  38. int block_size, torch::Tensor sorted_token_ids,
  39. torch::Tensor expert_ids,
  40. torch::Tensor num_tokens_post_pad);
  41. #ifndef USE_ROCM
  42. using fptr_t = uint64_t;
  43. fptr_t init_custom_ar(torch::Tensor& meta, torch::Tensor& rank_data,
  44. const std::vector<std::string>& handles,
  45. const std::vector<int64_t>& offsets, int rank,
  46. bool full_nvlink);
  47. bool should_custom_ar(torch::Tensor& inp, int max_size, int world_size,
  48. bool full_nvlink);
  49. void all_reduce_reg(fptr_t _fa, torch::Tensor& inp, torch::Tensor& out);
  50. void all_reduce_unreg(fptr_t _fa, torch::Tensor& inp, torch::Tensor& reg_buffer,
  51. torch::Tensor& out);
  52. void dispose(fptr_t _fa);
  53. int meta_size();
  54. void register_buffer(fptr_t _fa, torch::Tensor& t,
  55. const std::vector<std::string>& handles,
  56. const std::vector<int64_t>& offsets);
  57. std::pair<std::vector<uint8_t>, std::vector<int64_t>> get_graph_buffer_ipc_meta(
  58. fptr_t _fa);
  59. void register_graph_buffers(fptr_t _fa, const std::vector<std::string>& handles,
  60. const std::vector<std::vector<int64_t>>& offsets);
  61. #endif