ops.h 4.1 KB

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