Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/runtime/contrib/cutlass/fp16_group_gemm_runner_sm100.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

#include <tvm/runtime/logging.h>

#include <fstream>
#include <iostream>
#include <sstream>
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/contrib/cutlass/fp16_group_gemm_runner_sm90.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

#include <tvm/runtime/logging.h>

#include <fstream>
#include <iostream>
#include <sstream>
Expand Down
1 change: 1 addition & 0 deletions src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <float.h>
#include <tvm/ffi/extra/c_env_api.h>
#include <tvm/ffi/function.h>
#include <tvm/runtime/logging.h>
#include <tvm/runtime/tensor.h>

#include "cutlass/bfloat16.h"
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/contrib/cutlass/gemm_runner.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

#include <tvm/runtime/logging.h>

#include <fstream>
#include <iostream>
#include <sstream>
Expand Down
1 change: 1 addition & 0 deletions src/runtime/contrib/nvshmem/init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/runtime/disco/disco_worker.h>
#include <tvm/runtime/logging.h>

#include "../../cuda/cuda_common.h"

Expand Down
1 change: 1 addition & 0 deletions src/runtime/contrib/thrust/thrust.cu
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <tvm/ffi/extra/c_env_api.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/runtime/logging.h>

#include <algorithm>
#include <functional>
Expand Down
49 changes: 37 additions & 12 deletions src/runtime/contrib/vllm/attention_kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <float.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/runtime/logging.h>
#include <tvm/runtime/tensor.h>

#include <algorithm>
Expand Down Expand Up @@ -756,10 +757,10 @@ TVM_FFI_STATIC_INIT_BLOCK() {
namespace refl = tvm::ffi::reflection;
refl::GlobalDef().def(
"tvm.contrib.vllm.single_query_cached_kv_attention",
[](const DLTensor* query, const DLTensor* key_cache, const DLTensor* value_cache,
const DLTensor* block_tables, const DLTensor* context_lens, int block_size,
const DLTensor* max_context_len_tensor, // TODO(masahi): pass integer
DLTensor* exp_sums, DLTensor* max_logits, DLTensor* tmp_out, DLTensor* out) {
[](Tensor query, Tensor key_cache, Tensor value_cache, Tensor block_tables,
Tensor context_lens, int block_size,
Tensor max_context_len_tensor, // TODO(masahi): pass integer
Tensor exp_sums, Tensor max_logits, Tensor tmp_out, Tensor out) {
Comment thread
MasterJH5574 marked this conversation as resolved.
int num_seqs = query->shape[0];
int num_heads = query->shape[1];
int max_context_len = static_cast<int*>(max_context_len_tensor->data)[0];
Expand All @@ -768,13 +769,19 @@ TVM_FFI_STATIC_INIT_BLOCK() {
bool use_v1 =
max_context_len <= 8192 && (max_num_partitions == 1 || num_seqs * num_heads > 512);
if (use_v1) {
single_query_cached_kv_attention_v1(query, key_cache, value_cache, block_tables,
context_lens, block_size, max_context_len_tensor,
out);
single_query_cached_kv_attention_v1(
query.GetDLTensorPtr(), key_cache.GetDLTensorPtr(), value_cache.GetDLTensorPtr(),
block_tables.GetDLTensorPtr(), context_lens.GetDLTensorPtr(), block_size,
max_context_len_tensor.GetDLTensorPtr(), const_cast<DLTensor*>(out.GetDLTensorPtr()));
Comment thread
MasterJH5574 marked this conversation as resolved.
} else {
single_query_cached_kv_attention_v2(query, key_cache, value_cache, block_tables,
context_lens, block_size, max_context_len_tensor,
exp_sums, max_logits, tmp_out, out);
single_query_cached_kv_attention_v2(
query.GetDLTensorPtr(), key_cache.GetDLTensorPtr(), value_cache.GetDLTensorPtr(),
block_tables.GetDLTensorPtr(), context_lens.GetDLTensorPtr(), block_size,
max_context_len_tensor.GetDLTensorPtr(),
const_cast<DLTensor*>(exp_sums.GetDLTensorPtr()),
const_cast<DLTensor*>(max_logits.GetDLTensorPtr()),
const_cast<DLTensor*>(tmp_out.GetDLTensorPtr()),
const_cast<DLTensor*>(out.GetDLTensorPtr()));
}
});
}
Expand All @@ -784,9 +791,27 @@ TVM_FFI_STATIC_INIT_BLOCK() {
namespace refl = tvm::ffi::reflection;
refl::GlobalDef()
.def("tvm.contrib.vllm.single_query_cached_kv_attention_v1",
single_query_cached_kv_attention_v1)
[](Tensor query, Tensor key_cache, Tensor value_cache, Tensor block_tables,
Tensor context_lens, int block_size, Tensor max_context_len_tensor, Tensor out) {
Comment thread
MasterJH5574 marked this conversation as resolved.
single_query_cached_kv_attention_v1(
query.GetDLTensorPtr(), key_cache.GetDLTensorPtr(), value_cache.GetDLTensorPtr(),
block_tables.GetDLTensorPtr(), context_lens.GetDLTensorPtr(), block_size,
max_context_len_tensor.GetDLTensorPtr(),
const_cast<DLTensor*>(out.GetDLTensorPtr()));
})
.def("tvm.contrib.vllm.single_query_cached_kv_attention_v2",
single_query_cached_kv_attention_v2);
[](Tensor query, Tensor key_cache, Tensor value_cache, Tensor block_tables,
Tensor context_lens, int block_size, Tensor max_context_len_tensor, Tensor exp_sums,
Tensor max_logits, Tensor tmp_out, Tensor out) {
Comment thread
MasterJH5574 marked this conversation as resolved.
single_query_cached_kv_attention_v2(
query.GetDLTensorPtr(), key_cache.GetDLTensorPtr(), value_cache.GetDLTensorPtr(),
block_tables.GetDLTensorPtr(), context_lens.GetDLTensorPtr(), block_size,
max_context_len_tensor.GetDLTensorPtr(),
const_cast<DLTensor*>(exp_sums.GetDLTensorPtr()),
const_cast<DLTensor*>(max_logits.GetDLTensorPtr()),
const_cast<DLTensor*>(tmp_out.GetDLTensorPtr()),
const_cast<DLTensor*>(out.GetDLTensorPtr()));
});
}

} // namespace runtime
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/contrib/vllm/cache_kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
static_cast<const int*>(slot_mapping->data), key_stride, value_stride, num_heads,
head_size, block_size, vec_size);

return Array{key_cache, value_cache};
return ffi::Array<Tensor>{key_cache, value_cache};
})
.def("tvm.contrib.vllm.reconstruct_from_cache",
[](Tensor key_cache, Tensor value_cache, Tensor slot_mapping) {
Expand Down Expand Up @@ -182,7 +182,7 @@ TVM_FFI_STATIC_INIT_BLOCK() {
static_cast<scalar_t*>(value->data), key_stride, value_stride, num_heads,
head_size, block_size, vec_size);

return Array{key, value};
return ffi::Array<Tensor>{key, value};
})
.def("tvm.contrib.vllm.copy_blocks", [](ffi::Array<Tensor> key_value_caches,
Tensor block_mapping) {
Expand Down
Loading