From da752edaf56a0be654d40773d743659a1c094b6c Mon Sep 17 00:00:00 2001 From: jianyuzh Date: Sun, 31 Dec 2023 14:40:51 +0800 Subject: [PATCH] add GGML_LIST_DEVICE function --- CMakeLists.txt | 3 ++- README_sycl.md | 51 +++++++++++++++++++++++++++++++++++++++++++++----- ggml-sycl.cpp | 8 +++++++- run.sh | 1 + 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 51089c3b5..a2895692d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -474,13 +474,14 @@ if (LLAMA_SYCL) if (_sycl_support) add_compile_definitions(GGML_USE_CUBLAS) + #add_compile_definitions(GGML_SYCL_F16) #add_compile_options(-std=c++17 -O3 -fsycl) add_compile_options(-I/opt/intel/oneapi/compiler/2024.0/include) add_compile_options(-I/opt/intel/oneapi/compiler/2024.0/include/sycl) add_compile_options(-I/opt/intel/oneapi/dpcpp-ct/2024.0/include) add_compile_options(-I/opt/intel/oneapi/2024.0/include) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wno-narrowing") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl -L${MKLROOT}/lib") diff --git a/README_sycl.md b/README_sycl.md index e76b9bbb4..83b8a40cc 100644 --- a/README_sycl.md +++ b/README_sycl.md @@ -43,7 +43,17 @@ If you want to get more binary files, please change the build prject. 1. Install Intel oneAPI Base toolkit. -2. Setup Local +2. Build locally: + +``` +mkdir -p build +cd build +source /opt/intel/oneapi/setvars.sh +cmake .. -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx +cmake --build . --config Release -v +``` + +or ``` ./setup.sh @@ -56,17 +66,22 @@ If you want to get more binary files, please change the build prject. Run without parameter: ``` +export GGML_SYCL_LIST_DEVICE=1 ./build/bin/main ``` Check the id in startup log, like: -ggml_init_cublas: found 6 CUDA devices: + +``` +SYCL devices: Device 0: Intel(R) Arc(TM) A770 Graphics, compute capability 1.3 Device 1: Intel(R) FPGA Emulation Device, compute capability 1.2 Device 2: 13th Gen Intel(R) Core(TM) i7-13700K, compute capability 3.0 Device 3: Intel(R) Arc(TM) A770 Graphics, compute capability 3.0 Device 4: Intel(R) UHD Graphics 770, compute capability 3.0 Device 5: Intel(R) UHD Graphics 770, compute capability 1.3 +Exit for list devices task. unset GGML_SYCL_LIST_DEVICE to restore LLM work! +``` #### Put model file to folder **models** @@ -133,17 +148,21 @@ Run the command in command line or powershell. Run without parameter: ``` +set GGML_SYCL_LIST_DEVICE=1 .\x64\Release\llama.cpp.sycl.exe ``` - Check the id in startup log, like: -ggml_init_cublas: found 6 CUDA devices: + +``` +SYCL devices: Device 0: Intel(R) Arc(TM) A770 Graphics, compute capability 1.3 Device 1: Intel(R) FPGA Emulation Device, compute capability 1.2 Device 2: 13th Gen Intel(R) Core(TM) i7-13700K, compute capability 3.0 Device 3: Intel(R) Arc(TM) A770 Graphics, compute capability 3.0 Device 4: Intel(R) UHD Graphics 770, compute capability 3.0 Device 5: Intel(R) UHD Graphics 770, compute capability 1.3 +Exit for list devices task. unset GGML_SYCL_LIST_DEVICE to restore LLM work! +``` #### Put model file to folder **models** @@ -160,4 +179,26 @@ set GGML_SYCL_DEVICE=0 #### Run ``` .\run.bat -``` \ No newline at end of file +``` + +### Environment Variable + +#### Build + +|Name|Value|Function| +|-|-|-| +|LLAMA_SYCL|ON (mandatory)|Enable build with SYCL code path| +|CMAKE_C_COMPILER|icx|Use icx compiler for SYCL code path| +|CMAKE_CXX_COMPILER|icpx|use icpx for SYCL code path| +|GGML_SYCL_F16|OFF (default) or ON|Enable FP16 in computing| + + +#### Running + + +|Name|Value|Function| +|-|-|-| +|GGML_SYCL_DEVICE|0 (default) or 1|Set the device id used. List the device ids by **GGML_SYCL_LIST_DEVICE**| +|GGML_SYCL_DEBUG|0 (default) or 1|Enable log funciton by macro: GGML_SYCL_DEBUG| +|GGML_SYCL_LIST_DEVICE|0 (default) or 1|List the device ids only| + diff --git a/ggml-sycl.cpp b/ggml-sycl.cpp index 5a92185c0..16271f2aa 100644 --- a/ggml-sycl.cpp +++ b/ggml-sycl.cpp @@ -8282,7 +8282,6 @@ void print_devices(){ int get_sycl_env(const char* env_name, int default_val){ char * user_device_string = getenv(env_name); - printf("get_sycl_env=%s=%s\n", env_name, user_device_string); int user_number = default_val; unsigned n; @@ -8297,6 +8296,13 @@ int get_sycl_env(const char* env_name, int default_val){ void ggml_init_cublas() try { static bool initialized = false; if (!initialized) { + if (get_sycl_env("GGML_SYCL_LIST_DEVICE", 0)!=0){ + printf("SYCL devices:\n"); + print_devices(); + printf("Exit for list devices task. unset GGML_SYCL_LIST_DEVICE to restore LLM work!\n"); + std::exit(0); + } + g_ggml_sycl_debug = get_sycl_env("GGML_SYCL_DEBUG", 0); printf("g_ggml_sycl_debug=%d\n", g_ggml_sycl_debug); diff --git a/run.sh b/run.sh index 6ac5b2a51..15714240e 100755 --- a/run.sh +++ b/run.sh @@ -7,6 +7,7 @@ source /opt/intel/oneapi/setvars.sh export GGML_SYCL_DEVIC=0 export GGML_SYCL_DEBUG=1 +export GGML_SYCL_LIST_DEVICE=1 #./build/bin/main -m models/llama-2-7b.Q4_0.gguf -p "${INPUT1}" -e -n 400 -ngl 33 -c 2048 ./build/bin/main -m models/llama-2-7b.Q4_0.gguf -p "${INPUT2}" -n 400 -e -ngl 33