add GGML_LIST_DEVICE function

This commit is contained in:
jianyuzh 2023-12-31 14:40:51 +08:00 committed by Meng, Hengyu
parent 43f2c35859
commit da752edaf5
4 changed files with 56 additions and 7 deletions

View file

@ -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")

View file

@ -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
```
```
### 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|

View file

@ -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);

1
run.sh
View file

@ -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