[SYCL] use malloc to support both iGPU and dGPU in same time (#18992)
* use malloc to support both iGPU and dGPU in same time * support windows --------- Co-authored-by: Neo Zhang Jianyu <jianyu.zhang@intel.com>
This commit is contained in:
parent
b5b8fa1c8b
commit
cb6caca191
|
|
@ -1157,13 +1157,28 @@ static const char * ggml_backend_sycl_host_buffer_type_name(ggml_backend_buffer_
|
||||||
GGML_UNUSED(buft);
|
GGML_UNUSED(buft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void * aligned_malloc_host(size_t alignment, size_t size) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return _aligned_malloc(size, alignment);
|
||||||
|
#else
|
||||||
|
return aligned_alloc(alignment, size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void free_aligned_mem_host(void * memblock) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
_aligned_free(memblock);
|
||||||
|
#else
|
||||||
|
free(memblock);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static void ggml_backend_sycl_host_buffer_free_buffer(ggml_backend_buffer_t buffer) {
|
static void ggml_backend_sycl_host_buffer_free_buffer(ggml_backend_buffer_t buffer) {
|
||||||
ggml_sycl_host_free(buffer->context);
|
free_aligned_mem_host((void *)buffer->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ggml_backend_buffer_t ggml_backend_sycl_host_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) {
|
static ggml_backend_buffer_t ggml_backend_sycl_host_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) {
|
||||||
void * ptr = ggml_sycl_host_malloc(size);
|
void * ptr = aligned_malloc_host(TENSOR_ALIGNMENT, size);
|
||||||
|
|
||||||
if (ptr == nullptr) {
|
if (ptr == nullptr) {
|
||||||
// fallback to cpu buffer
|
// fallback to cpu buffer
|
||||||
return ggml_backend_buft_alloc_buffer(ggml_backend_cpu_buffer_type(), size);
|
return ggml_backend_buft_alloc_buffer(ggml_backend_cpu_buffer_type(), size);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue