Kernels
File size: 3,589 Bytes
57c3a10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <torch/library.h>

#include "registration.h"
#include "torch_binding.h"
    
TORCH_LIBRARY_EXPAND(TORCH_EXTENSION_NAME, ops) {

  ops.def("gelu_and_mul(Tensor! out, Tensor! input, bool enable_pdl) -> ()");
  ops.impl("gelu_and_mul", torch::kCUDA, &gelu_and_mul);

  ops.def("gelu_tanh_and_mul(Tensor! out, Tensor! input, bool enable_pdl) -> ()");
  ops.impl("gelu_tanh_and_mul", torch::kCUDA, &gelu_tanh_and_mul);

  ops.def("silu_and_mul(Tensor! out, Tensor! input, bool enable_pdl) -> ()");
  ops.impl("silu_and_mul", torch::kCUDA, &silu_and_mul);

  // Register variant-specific operators directly
  // ops.def(
  //   "BatchDecodeWithPagedKVCachePlan_swa_false("
  //   "Tensor float_workspace_buffer, "
  //   "Tensor int_workspace_buffer, "
  //   "Tensor page_locked_int_workspace_buffer, "
  //   "Tensor indptr, "
  //   "int batch_size, "
  //   "int num_qo_heads, "
  //   "int num_kv_heads, "
  //   "int page_size, "
  //   "bool enable_cuda_graph, "
  //   "int window_left, "
  //   "float logits_soft_cap, "
  //   "int head_dim_qk, "
  //   "int head_dim_vo, "
  //   "Tensor empty_q_data, "
  //   "Tensor empty_kv_data) -> Tensor"
  // );
  // ops.impl("BatchDecodeWithPagedKVCachePlan_swa_false", torch::kCUDA, &BatchDecodeWithPagedKVCachePlan_swa_false);

  // ops.def(
  //   "BatchDecodeWithPagedKVCacheRun_swa_false("
  //   "Tensor float_workspace_buffer, "
  //   "Tensor int_workspace_buffer, "
  //   "Tensor plan_info_vec, "
  //   "Tensor q, "
  //   "Tensor paged_k_cache, "
  //   "Tensor paged_v_cache, "
  //   "Tensor paged_kv_indptr, "
  //   "Tensor paged_kv_indices, "
  //   "Tensor paged_kv_last_page_len, "
  //   "Tensor o, "
  //   "Tensor? maybe_lse, "
  //   "int kv_layout_code, "
  //   "int window_left, "
  //   "bool enable_pdl, "
  //   "Tensor? maybe_alibi_slopes, "
  //   "float logits_soft_cap, "
  //   "float sm_scale, "
  //   "float rope_rcp_scale, "
  //   "float rope_rcp_theta) -> ()"
  // );
  // ops.impl("BatchDecodeWithPagedKVCacheRun_swa_false", torch::kCUDA, &BatchDecodeWithPagedKVCacheRun_swa_false);

  // ops.def(
  //   "BatchDecodeWithPagedKVCachePlan_swa_true("
  //   "Tensor float_workspace_buffer, "
  //   "Tensor int_workspace_buffer, "
  //   "Tensor page_locked_int_workspace_buffer, "
  //   "Tensor indptr, "
  //   "int batch_size, "
  //   "int num_qo_heads, "
  //   "int num_kv_heads, "
  //   "int page_size, "
  //   "bool enable_cuda_graph, "
  //   "int window_left, "
  //   "float logits_soft_cap, "
  //   "int head_dim_qk, "
  //   "int head_dim_vo, "
  //   "Tensor empty_q_data, "
  //   "Tensor empty_kv_data) -> Tensor"
  // );
  // ops.impl("BatchDecodeWithPagedKVCachePlan_swa_true", torch::kCUDA, &BatchDecodeWithPagedKVCachePlan_swa_true);

  // ops.def(
  //   "BatchDecodeWithPagedKVCacheRun_swa_true("
  //   "Tensor float_workspace_buffer, "
  //   "Tensor int_workspace_buffer, "
  //   "Tensor plan_info_vec, "
  //   "Tensor q, "
  //   "Tensor paged_k_cache, "
  //   "Tensor paged_v_cache, "
  //   "Tensor paged_kv_indptr, "
  //   "Tensor paged_kv_indices, "
  //   "Tensor paged_kv_last_page_len, "
  //   "Tensor o, "
  //   "Tensor? maybe_lse, "
  //   "int kv_layout_code, "
  //   "int window_left, "
  //   "bool enable_pdl, "
  //   "Tensor? maybe_alibi_slopes, "
  //   "float logits_soft_cap, "
  //   "float sm_scale, "
  //   "float rope_rcp_scale, "
  //   "float rope_rcp_theta) -> ()"
  // );
  // ops.impl("BatchDecodeWithPagedKVCacheRun_swa_true", torch::kCUDA, &BatchDecodeWithPagedKVCacheRun_swa_true);
}

REGISTER_EXTENSION(TORCH_EXTENSION_NAME)