mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-10-28 08:31:25 +00:00 
			
		
		
		
	Add an option to build without CUDA VMM (#7067)
Add an option to build ggml cuda without CUDA VMM resolves https://github.com/ggerganov/llama.cpp/issues/6889 https://forums.developer.nvidia.com/t/potential-nvshmem-allocated-memory-performance-issue/275416/4
This commit is contained in:
		 William Tambellini
					William Tambellini
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							b3a995b416
						
					
				
				
					commit
					858f6b73f6
				
			| @@ -103,6 +103,8 @@ set(LLAMA_CUDA_KQUANTS_ITER "2" CACHE STRING "llama: iters./thread per block for | |||||||
| set(LLAMA_CUDA_PEER_MAX_BATCH_SIZE "128" CACHE STRING | set(LLAMA_CUDA_PEER_MAX_BATCH_SIZE "128" CACHE STRING | ||||||
|                                              "llama: max. batch size for using peer access") |                                              "llama: max. batch size for using peer access") | ||||||
| option(LLAMA_CUDA_NO_PEER_COPY               "llama: do not use peer to peer copies"            OFF) | option(LLAMA_CUDA_NO_PEER_COPY               "llama: do not use peer to peer copies"            OFF) | ||||||
|  | option(LLAMA_CUDA_NO_VMM                     "llama: do not try to use CUDA VMM"                OFF) | ||||||
|  |  | ||||||
| option(LLAMA_CURL                            "llama: use libcurl to download model from an URL" OFF) | option(LLAMA_CURL                            "llama: use libcurl to download model from an URL" OFF) | ||||||
| option(LLAMA_HIPBLAS                         "llama: use hipBLAS"                               OFF) | option(LLAMA_HIPBLAS                         "llama: use hipBLAS"                               OFF) | ||||||
| option(LLAMA_HIP_UMA                         "llama: use HIP unified memory architecture"       OFF) | option(LLAMA_HIP_UMA                         "llama: use HIP unified memory architecture"       OFF) | ||||||
| @@ -409,6 +411,9 @@ if (LLAMA_CUDA) | |||||||
|         if (LLAMA_CUDA_FORCE_MMQ) |         if (LLAMA_CUDA_FORCE_MMQ) | ||||||
|             add_compile_definitions(GGML_CUDA_FORCE_MMQ) |             add_compile_definitions(GGML_CUDA_FORCE_MMQ) | ||||||
|         endif() |         endif() | ||||||
|  |         if (LLAMA_CUDA_NO_VMM) | ||||||
|  |             add_compile_definitions(GGML_CUDA_NO_VMM) | ||||||
|  |         endif() | ||||||
|         add_compile_definitions(GGML_CUDA_DMMV_X=${LLAMA_CUDA_DMMV_X}) |         add_compile_definitions(GGML_CUDA_DMMV_X=${LLAMA_CUDA_DMMV_X}) | ||||||
|         add_compile_definitions(GGML_CUDA_MMV_Y=${LLAMA_CUDA_MMV_Y}) |         add_compile_definitions(GGML_CUDA_MMV_Y=${LLAMA_CUDA_MMV_Y}) | ||||||
|         if (DEFINED LLAMA_CUDA_DMMV_Y) |         if (DEFINED LLAMA_CUDA_DMMV_Y) | ||||||
| @@ -434,7 +439,11 @@ if (LLAMA_CUDA) | |||||||
|             set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} CUDA::cudart CUDA::cublas CUDA::cublasLt) |             set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} CUDA::cudart CUDA::cublas CUDA::cublasLt) | ||||||
|         endif() |         endif() | ||||||
|  |  | ||||||
|         set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} CUDA::cuda_driver) |         if (LLAMA_CUDA_NO_VMM) | ||||||
|  |             # No VMM requested, no need to link directly with the cuda driver lib (libcuda.so) | ||||||
|  |         else() | ||||||
|  |             set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} CUDA::cuda_driver) # required by cuDeviceGetAttribute(), cuMemGetAllocationGranularity(...), ... | ||||||
|  |         endif() | ||||||
|  |  | ||||||
|     if (NOT DEFINED CMAKE_CUDA_ARCHITECTURES) |     if (NOT DEFINED CMAKE_CUDA_ARCHITECTURES) | ||||||
|         # 52 == lowest CUDA 12 standard |         # 52 == lowest CUDA 12 standard | ||||||
|   | |||||||
| @@ -113,7 +113,7 @@ static ggml_cuda_device_info ggml_cuda_init() { | |||||||
|     for (int id = 0; id < info.device_count; ++id) { |     for (int id = 0; id < info.device_count; ++id) { | ||||||
|         int device_vmm = 0; |         int device_vmm = 0; | ||||||
|  |  | ||||||
| #if !defined(GGML_USE_HIPBLAS) | #if !defined(GGML_USE_HIPBLAS) && !defined(GGML_CUDA_NO_VMM) | ||||||
|         CUdevice device; |         CUdevice device; | ||||||
|         CU_CHECK(cuDeviceGet(&device, id)); |         CU_CHECK(cuDeviceGet(&device, id)); | ||||||
|         CU_CHECK(cuDeviceGetAttribute(&device_vmm, CU_DEVICE_ATTRIBUTE_VIRTUAL_MEMORY_MANAGEMENT_SUPPORTED, device)); |         CU_CHECK(cuDeviceGetAttribute(&device_vmm, CU_DEVICE_ATTRIBUTE_VIRTUAL_MEMORY_MANAGEMENT_SUPPORTED, device)); | ||||||
| @@ -259,7 +259,7 @@ struct ggml_cuda_pool_leg : public ggml_cuda_pool { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| // pool with virtual memory | // pool with virtual memory | ||||||
| #if !defined(GGML_USE_HIPBLAS) | #if !defined(GGML_USE_HIPBLAS) && !defined(GGML_CUDA_NO_VMM) | ||||||
| struct ggml_cuda_pool_vmm : public ggml_cuda_pool { | struct ggml_cuda_pool_vmm : public ggml_cuda_pool { | ||||||
|     static const size_t CUDA_POOL_VMM_MAX_SIZE = 1ull << 35; // 32 GB |     static const size_t CUDA_POOL_VMM_MAX_SIZE = 1ull << 35; // 32 GB | ||||||
|  |  | ||||||
| @@ -356,7 +356,7 @@ struct ggml_cuda_pool_vmm : public ggml_cuda_pool { | |||||||
| #endif // !defined(GGML_USE_HIPBLAS) | #endif // !defined(GGML_USE_HIPBLAS) | ||||||
|  |  | ||||||
| std::unique_ptr<ggml_cuda_pool> ggml_backend_cuda_context::new_pool_for_device(int device) { | std::unique_ptr<ggml_cuda_pool> ggml_backend_cuda_context::new_pool_for_device(int device) { | ||||||
| #if !defined(GGML_USE_HIPBLAS) | #if !defined(GGML_USE_HIPBLAS) && !defined(GGML_CUDA_NO_VMM) | ||||||
|     if (ggml_cuda_info().devices[device].vmm) { |     if (ggml_cuda_info().devices[device].vmm) { | ||||||
|         return std::unique_ptr<ggml_cuda_pool>(new ggml_cuda_pool_vmm(device)); |         return std::unique_ptr<ggml_cuda_pool>(new ggml_cuda_pool_vmm(device)); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user