mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-11-04 09:32:00 +00:00 
			
		
		
		
	* sycl: fix im2col overflow and sync with cuda Signed-off-by: zhentaoyu <zhentao.yu@intel.com> * sycl: fix convert overflow Signed-off-by: zhentaoyu <zhentao.yu@intel.com> * sycl: fix convert and dequantize Signed-off-by: zhentaoyu <zhentao.yu@intel.com> * sycl: fix ib in dmmv Signed-off-by: zhentaoyu <zhentao.yu@intel.com> * sycl:refine convert Signed-off-by: zhentaoyu <zhentao.yu@intel.com> * sycl: move downsample global_range into common Signed-off-by: zhentaoyu <zhentao.yu@intel.com> * test: add im2col and convert test cases Signed-off-by: zhentaoyu <zhentao.yu@intel.com> * test: make new cases only in sycl Signed-off-by: zhentaoyu <zhentao.yu@intel.com> * test: comment new test_cases for only local testing Signed-off-by: zhentaoyu <zhentao.yu@intel.com> --------- Signed-off-by: zhentaoyu <zhentao.yu@intel.com>
		
			
				
	
	
		
			65 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
//
 | 
						|
// MIT license
 | 
						|
// Copyright (C) 2024 Intel Corporation
 | 
						|
// SPDX-License-Identifier: MIT
 | 
						|
//
 | 
						|
 | 
						|
//
 | 
						|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 | 
						|
// See https://llvm.org/LICENSE.txt for license information.
 | 
						|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 | 
						|
//
 | 
						|
 | 
						|
#include "common.hpp"
 | 
						|
 | 
						|
int get_current_device_id() {
 | 
						|
  return dpct::dev_mgr::instance().current_device_id();
 | 
						|
}
 | 
						|
 | 
						|
void* ggml_sycl_host_malloc(size_t size) try {
 | 
						|
  if (getenv("GGML_SYCL_NO_PINNED") != nullptr) {
 | 
						|
    return nullptr;
 | 
						|
  }
 | 
						|
 | 
						|
  void* ptr = nullptr;
 | 
						|
  // allow to use dpct::get_in_order_queue() for host malloc
 | 
						|
  dpct::err0 err = CHECK_TRY_ERROR(
 | 
						|
      ptr = (void*)sycl::malloc_host(size, dpct::get_in_order_queue()));
 | 
						|
 | 
						|
  if (err != 0) {
 | 
						|
    // clear the error
 | 
						|
    fprintf(
 | 
						|
        stderr,
 | 
						|
        "WARNING: failed to allocate %.2f MB of pinned memory: %s\n",
 | 
						|
        size / 1024.0 / 1024.0,
 | 
						|
        "syclGetErrorString is not supported");
 | 
						|
    return nullptr;
 | 
						|
  }
 | 
						|
 | 
						|
  return ptr;
 | 
						|
} catch (sycl::exception const& exc) {
 | 
						|
  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
 | 
						|
            << ", line:" << __LINE__ << std::endl;
 | 
						|
  std::exit(1);
 | 
						|
}
 | 
						|
 | 
						|
void ggml_sycl_host_free(void* ptr) try {
 | 
						|
  // allow to use dpct::get_in_order_queue() for host malloc
 | 
						|
  SYCL_CHECK(CHECK_TRY_ERROR(sycl::free(ptr, dpct::get_in_order_queue())));
 | 
						|
} catch (sycl::exception const& exc) {
 | 
						|
  std::cerr << exc.what() << "Exception caught at file:" << __FILE__
 | 
						|
            << ", line:" << __LINE__ << std::endl;
 | 
						|
  std::exit(1);
 | 
						|
}
 | 
						|
 | 
						|
int64_t downsample_sycl_global_range(int64_t accumulate_block_num, int64_t block_size) {
 | 
						|
  const int64_t max_range = std::numeric_limits<int>::max();
 | 
						|
  int64_t sycl_down_blk_size = block_size;
 | 
						|
  int64_t global_range = accumulate_block_num * sycl_down_blk_size;
 | 
						|
  while(global_range > max_range) {
 | 
						|
      sycl_down_blk_size /= 2;
 | 
						|
      global_range = accumulate_block_num * sycl_down_blk_size;
 | 
						|
  }
 | 
						|
  return sycl_down_blk_size;
 | 
						|
}
 |