File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -349,6 +349,10 @@ set(_aoti_cuda_backend_sources
349349 runtime/cuda_backend.cpp runtime/cuda_mutable_state.cpp
350350 runtime/cuda_weight_cache.cpp
351351)
352+ # The off-graph KV cache builds on the LLM extension's neutral cache.
353+ if (EXECUTORCH_BUILD_EXTENSION_LLM)
354+ list (APPEND _aoti_cuda_backend_sources runtime/cuda_kv_cache.cpp)
355+ endif ()
352356if (_cuda_is_msvc_toolchain)
353357 # MSVC links aoti_cuda_backend into portable_lib without relying on C++
354358 # symbols exported from aoti_cuda_shims.dll.
@@ -401,6 +405,9 @@ target_link_libraries(
401405 PUBLIC cuda_platform extension_tensor ${_cuda_runtime_libraries}
402406 extension_cuda ${CMAKE_DL_LIBS }
403407)
408+ if (EXECUTORCH_BUILD_EXTENSION_LLM)
409+ target_link_libraries (aoti_cuda_backend PUBLIC extension_llm_cache )
410+ endif ()
404411
405412if (_cuda_is_msvc_toolchain)
406413 # cuda_backend.cpp uses SlimTensor CUDA utilities (e.g. getCurrentCUDAStream)
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3+ * All rights reserved.
4+ *
5+ * This source code is licensed under the BSD-style license found in the
6+ * LICENSE file in the root directory of this source tree.
7+ */
8+
9+ #pragma once
10+
11+ namespace executorch ::backends::cuda {
12+
13+ // Shared identifiers for the CUDA backend. Included by the backend itself (to
14+ // register) and by callers/runners (to route backend options and to ask
15+ // CacheFactory for a builder), keeping the string literals in one place.
16+
17+ // Backend id under which the CUDA backend registers (see cuda_backend.cpp).
18+ inline constexpr char kCudaBackendId [] = " CudaBackend" ;
19+
20+ } // namespace executorch::backends::cuda
Original file line number Diff line number Diff line change @@ -202,6 +202,8 @@ class ET_EXPERIMENTAL CudaBackend final
202202 AOTInductorModelContainerGetConstantOriginalFQN);
203203 LOAD_OPTIONAL_SYMBOL (
204204 get_constant_dtype, AOTInductorModelContainerGetConstantDtype);
205+ LOAD_OPTIONAL_SYMBOL (
206+ get_constant_data_size, AOTInductorModelContainerGetConstantDataSize);
205207 LOAD_OPTIONAL_SYMBOL (
206208 extract_constants_map, AOTInductorModelContainerExtractConstantsMap);
207209 LOAD_OPTIONAL_SYMBOL (
Original file line number Diff line number Diff line change @@ -26,6 +26,11 @@ using AOTInductorModelContainerGetConstantDtypeFunc =
2626 aoti::AOTInductorModelContainerHandle container_handle,
2727 size_t idx,
2828 int32_t * dtype);
29+ using AOTInductorModelContainerGetConstantDataSizeFunc =
30+ aoti::AOTIRuntimeError (*)(
31+ aoti::AOTInductorModelContainerHandle container_handle,
32+ size_t idx,
33+ size_t * data_size);
2934struct CudaWeightStorage {
3035 void * data{nullptr };
3136 size_t nbytes{0 };
@@ -170,6 +175,10 @@ struct CudaGraphState {
170175struct CudaDelegateHandle : public aoti ::AOTIDelegateHandle {
171176 // Extra AOTI metadata used to validate per-FQN weights before binding.
172177 AOTInductorModelContainerGetConstantDtypeFunc get_constant_dtype{nullptr };
178+ // Bytes a constant's compiled shape spans; the off-graph KV cache checks its
179+ // storage against it before binding.
180+ AOTInductorModelContainerGetConstantDataSizeFunc get_constant_data_size{
181+ nullptr };
173182
174183 // The per-thread stream. Nothing owns it: the value is a fixed sentinel the
175184 // driver resolves to a different stream on each host thread, so releasing the
You can’t perform that action at this time.
0 commit comments