Skip to content

Commit 72b74f3

Browse files
committed
cuda : do not create buffer types for devices that don't exist (fixes usage without CUDA devices available)
1 parent 2f2c367 commit 72b74f3

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

ggml-cuda.cu

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9568,6 +9568,10 @@ static ggml_backend_buffer_type_i ggml_backend_cuda_buffer_type_interface = {
95689568

95699569
ggml_backend_buffer_type_t ggml_backend_cuda_buffer_type(int device) {
95709570
// FIXME: this is not thread safe
9571+
if (device >= ggml_backend_cuda_get_device_count()) {
9572+
return nullptr;
9573+
}
9574+
95719575
static struct ggml_backend_buffer_type ggml_backend_cuda_buffer_types[GGML_CUDA_MAX_DEVICES];
95729576

95739577
static bool ggml_backend_cuda_buffer_type_initialized = false;
@@ -9793,7 +9797,6 @@ ggml_backend_buffer_type_t ggml_backend_cuda_split_buffer_type(const float * ten
97939797
// FIXME: this is not thread safe
97949798
static std::map<std::array<float, GGML_CUDA_MAX_DEVICES>, struct ggml_backend_buffer_type> buft_map;
97959799

9796-
97979800
std::array<float, GGML_CUDA_MAX_DEVICES> tensor_split_arr = {};
97989801

97999802
bool all_zero = tensor_split == nullptr || std::all_of(tensor_split, tensor_split + GGML_CUDA_MAX_DEVICES, [](float x) { return x == 0.0f; });

ggml-cuda.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ GGML_API int ggml_backend_cuda_get_device_count(void);
4747
GGML_API void ggml_backend_cuda_get_device_description(int device, char * description, size_t description_size);
4848
GGML_API void ggml_backend_cuda_get_device_memory(int device, size_t * free, size_t * total);
4949

50-
51-
5250
#ifdef __cplusplus
5351
}
5452
#endif

0 commit comments

Comments
 (0)