Skip to content

Commit cb6caca

Browse files
[SYCL] use malloc to support both iGPU and dGPU in same time (ggml-org#18992)
* use malloc to support both iGPU and dGPU in same time * support windows --------- Co-authored-by: Neo Zhang Jianyu <jianyu.zhang@intel.com>
1 parent b5b8fa1 commit cb6caca

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

ggml/src/ggml-sycl/ggml-sycl.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,13 +1157,28 @@ static const char * ggml_backend_sycl_host_buffer_type_name(ggml_backend_buffer_
11571157
GGML_UNUSED(buft);
11581158
}
11591159

1160+
inline void * aligned_malloc_host(size_t alignment, size_t size) {
1161+
#ifdef _WIN32
1162+
return _aligned_malloc(size, alignment);
1163+
#else
1164+
return aligned_alloc(alignment, size);
1165+
#endif
1166+
}
1167+
1168+
inline void free_aligned_mem_host(void * memblock) {
1169+
#ifdef _WIN32
1170+
_aligned_free(memblock);
1171+
#else
1172+
free(memblock);
1173+
#endif
1174+
}
1175+
11601176
static void ggml_backend_sycl_host_buffer_free_buffer(ggml_backend_buffer_t buffer) {
1161-
ggml_sycl_host_free(buffer->context);
1177+
free_aligned_mem_host((void *)buffer->context);
11621178
}
11631179

11641180
static ggml_backend_buffer_t ggml_backend_sycl_host_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) {
1165-
void * ptr = ggml_sycl_host_malloc(size);
1166-
1181+
void * ptr = aligned_malloc_host(TENSOR_ALIGNMENT, size);
11671182
if (ptr == nullptr) {
11681183
// fallback to cpu buffer
11691184
return ggml_backend_buft_alloc_buffer(ggml_backend_cpu_buffer_type(), size);

0 commit comments

Comments
 (0)