cache.cpp 564 Bytes
Newer Older
Woosuk Kwon's avatar
Woosuk Kwon committed
1
2
3
4
5
6
7
#include <torch/extension.h>

void copy_blocks(
  torch::Tensor& src,
  torch::Tensor& dst,
  const std::map<int64_t, int64_t>& block_mapping);

Woosuk Kwon's avatar
Woosuk Kwon committed
8
9
10
11
12
13
14
void reshape_and_cache(
  torch::Tensor& key,
  torch::Tensor& value,
  torch::Tensor& key_cache,
  torch::Tensor& value_cache,
  torch::Tensor& slot_mapping);

Woosuk Kwon's avatar
Woosuk Kwon committed
15
16
17
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
  m.def(
    "copy_cache_blocks",
Woosuk Kwon's avatar
Woosuk Kwon committed
18
    &copy_blocks,
Woosuk Kwon's avatar
Woosuk Kwon committed
19
    "Copy the cache blocks from src to dst");
Woosuk Kwon's avatar
Woosuk Kwon committed
20
21
22
23
  m.def(
    "reshape_and_cache",
    &reshape_and_cache,
    "Reshape the key and value tensors and cache them");
Woosuk Kwon's avatar
Woosuk Kwon committed
24
}