diff --git a/ds4.c b/ds4.c index 640511eb0..a96795f75 100644 --- a/ds4.c +++ b/ds4.c @@ -90,11 +90,9 @@ static bool ds4_backend_supports_ssd_streaming(ds4_backend backend) { static bool ds4_backend_supports_streaming_auto_cache(ds4_backend backend) { if (backend == DS4_BACKEND_METAL) return true; -#ifdef DS4_ROCM_BUILD + /* CUDA now has a working ds4_gpu_recommended_working_set_size() + * implementation, so the auto cache planner can run here too. */ if (backend == DS4_BACKEND_CUDA) return true; -#else - (void)backend; -#endif return false; } diff --git a/ds4_cuda.cu b/ds4_cuda.cu index 188b341ad..5c8e825a1 100644 --- a/ds4_cuda.cu +++ b/ds4_cuda.cu @@ -2781,7 +2781,19 @@ extern "C" void ds4_gpu_set_streaming_expert_cache_expert_bytes(uint64_t bytes) } extern "C" uint64_t ds4_gpu_recommended_working_set_size(void) { - return 0; + /* Metal exposes recommendedMaxWorkingSetSize natively; CUDA has no + * direct equivalent, so use total device memory as the closest + * analogue. The 80% margin applied by callers (see + * ds4_ssd_auto_cache_plan) accounts for KV cache, activations and + * driver overhead. */ + size_t free_bytes = 0, total_bytes = 0; + cudaError_t err = cudaMemGetInfo(&free_bytes, &total_bytes); + (void)free_bytes; + if (err != cudaSuccess) { + (void)cudaGetLastError(); + return 0; + } + return (uint64_t)total_bytes; } extern "C" uint32_t ds4_gpu_stream_expert_cache_configured_count(void) {