diff --git a/CMakeLists.txt b/CMakeLists.txt index e047785e603d6..a4d51cdbe2dc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,8 @@ if (GGML_TSAVORITE) if (NOT DEFINED MLIR_COMPILER_DIR) if (NOT DEFINED $ENV{MLIR_SDK_VERSION}) - set (MLIR_COMPILER_DIR /proj/work/rel/sw/sdk-r.0.1.2/compiler) + set (MLIR_COMPILER_DIR /proj/rel/sw/sdk-r.0.1.3/compiler) + message("MLIR_SDK_VERSION not set defaulting to ${MLIR_COMPILER_DIR}") else() set (MLIR_COMPILER_DIR $ENV{MLIR_SDK_VERSION}/compiler) endif() @@ -23,7 +24,8 @@ if (GGML_TSAVORITE) if (NOT DEFINED RUNTIME_DIR) if (NOT DEFINED $ENV{MLIR_SDK_VERSION}) - set (RUNTIME_DIR /proj/work/rel/sw/sdk-r.0.1.2/${GGML_TSAVORITE_TARGET}/runtime) + set (RUNTIME_DIR /proj/rel/sw/sdk-r.0.1.3/${GGML_TSAVORITE_TARGET}/runtime) + message("MLIR_SDK_VERSION not set defaulting to ${RUNTIME_DIR}") else() set (RUNTIME_DIR $ENV{MLIR_SDK_VERSION}/${GGML_TSAVORITE_TARGET}/runtime) endif() @@ -33,14 +35,14 @@ if (GGML_TSAVORITE) set (GGML_TSI_KERNEL_DIR ${CMAKE_SOURCE_DIR}/ggml-tsi-kernel/${GGML_TSAVORITE_TARGET}) endif() - file(GLOB TLIBS "${RUNTIME_DIR}/lib/*.so" "${GGML_TSI_KERNEL_DIR}/host/*.o") if (${GGML_TSAVORITE_TARGET} STREQUAL fpga) set(CMAKE_CROSSCOMPILING ON) set(ARCH_FLAGS -march=armv8-a) + file(GLOB TLIBS "${RUNTIME_DIR}/lib/*.so" "${GGML_TSI_KERNEL_DIR}/host/*.o" "${RUNTIME_DIR}/../utils/lib/TsavRTShimCAPI.cpp.o") message("Setting target as fpga") elseif (${GGML_TSAVORITE_TARGET} STREQUAL "posix") - list(APPEND TLIBS "${MLIR_COMPILER_DIR}/lib/libFFMDeviceShim.so") + file(GLOB TLIBS "${RUNTIME_DIR}/lib/*.so" "${GGML_TSI_KERNEL_DIR}/host/*.o" "${MLIR_COMPILER_DIR}/lib/libFFMDeviceShim.so" "${MLIR_COMPILER_DIR}/lib/libTsavRTPosixShimCAPI.so") message("Setting target as posix for tsavorite") endif() diff --git a/ggml-tsi-kernel b/ggml-tsi-kernel index d1383a04f29d0..9dcf09f210636 160000 --- a/ggml-tsi-kernel +++ b/ggml-tsi-kernel @@ -1 +1 @@ -Subproject commit d1383a04f29d0160750c0e51ab524d461c6a127b +Subproject commit 9dcf09f2106364d0dafa54bce743d1c11b701112 diff --git a/ggml/include/ggml-tsavorite.h b/ggml/include/ggml-tsavorite.h index 54a8e34662799..238dcc428da88 100644 --- a/ggml/include/ggml-tsavorite.h +++ b/ggml/include/ggml-tsavorite.h @@ -151,16 +151,16 @@ typedef struct tensor_log_ { const ggml_tensor *tensor; } tensor_log; -extern void _mlir_ciface_txe_add(void *a, void *b, void *res); -extern void _mlir_ciface_txe_sub(void *a, void *b, void *res); -extern void _mlir_ciface_txe_mult(void *a, void *b, void *res); -extern void _mlir_ciface_txe_div(void *a, void *b, void *res); -extern void _mlir_ciface_txe_sqrt(void *a, void *res); -extern void _mlir_ciface_txe_neg(void *a, void *res); -extern void _mlir_ciface_txe_abs(void *a, void *res); -extern void _mlir_ciface_txe_sin(void *a, void *res); -extern void _mlir_ciface_txe_sigmoid(void *a, void *res); -extern void _mlir_ciface_txe_silu(void *a, void *res); +extern void _mlir_ciface_txe_add_host(void *a, void *b, void *res); +extern void _mlir_ciface_txe_sub_host(void *a, void *b, void *res); +extern void _mlir_ciface_txe_mult_host(void *a, void *b, void *res); +extern void _mlir_ciface_txe_div_host(void *a, void *b, void *res); +extern void _mlir_ciface_txe_sqrt_host(void *a, void *res); +extern void _mlir_ciface_txe_neg_host(void *a, void *res); +extern void _mlir_ciface_txe_abs_host(void *a, void *res); +extern void _mlir_ciface_txe_sin_host(void *a, void *res); +extern void _mlir_ciface_txe_sigmoid_host(void *a, void *res); +extern void _mlir_ciface_txe_silu_host(void *a, void *res); extern void ggml_tsi_log_tensor_data(tensor_log log_data); #define NUM_OF_TXES 1 diff --git a/ggml/src/ggml-tsavorite/ggml-tsavorite.cpp b/ggml/src/ggml-tsavorite/ggml-tsavorite.cpp index 573220c8a7027..bc7095eeebf2f 100644 --- a/ggml/src/ggml-tsavorite/ggml-tsavorite.cpp +++ b/ggml/src/ggml-tsavorite/ggml-tsavorite.cpp @@ -389,12 +389,12 @@ static txe_compute_pipeline_state_s tsi_kernel_setup(enum ggml_tsavorite_kernel_ if (ggml_tsavorite_kernel_mode_flag == GGML_TSAVORITE_KERNEL_MODE_CPU) kernel_pipeline->_mlir_fptr_2_input = &_mlir_ciface_txe_add_test; else - kernel_pipeline->_mlir_fptr_2_input = &_mlir_ciface_txe_add; + kernel_pipeline->_mlir_fptr_2_input = &_mlir_ciface_txe_add_host; kernel_pipeline->kernel_name = "TXE_ADD"; flag = true; break; case GGML_TSAVORITE_KERNEL_TYPE_SUB: - kernel_pipeline->_mlir_fptr_2_input = &_mlir_ciface_txe_sub; + kernel_pipeline->_mlir_fptr_2_input = &_mlir_ciface_txe_sub_host; kernel_pipeline->kernel_name = "TXE_SUB"; flag = true; break; @@ -402,42 +402,42 @@ static txe_compute_pipeline_state_s tsi_kernel_setup(enum ggml_tsavorite_kernel_ if (ggml_tsavorite_kernel_mode_flag == GGML_TSAVORITE_KERNEL_MODE_CPU) kernel_pipeline->_mlir_fptr_2_input = &_mlir_ciface_txe_mult_test; else - kernel_pipeline->_mlir_fptr_2_input = &_mlir_ciface_txe_mult; + kernel_pipeline->_mlir_fptr_2_input = &_mlir_ciface_txe_mult_host; kernel_pipeline->kernel_name = "TXE_MULT"; flag = true; break; case GGML_TSAVORITE_KERNEL_TYPE_DIV: - kernel_pipeline->_mlir_fptr_2_input = &_mlir_ciface_txe_div; + kernel_pipeline->_mlir_fptr_2_input = &_mlir_ciface_txe_div_host; kernel_pipeline->kernel_name = "TXE_DIV"; flag = true; break; case GGML_TSAVORITE_KERNEL_TYPE_SQRT: - kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_sqrt; + kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_sqrt_host; kernel_pipeline->kernel_name = "TXE_SQRT"; flag = true; break; case GGML_TSAVORITE_KERNEL_TYPE_NEG: - kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_neg; + kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_neg_host; kernel_pipeline->kernel_name = "TXE_NEG"; flag = true; break; case GGML_TSAVORITE_KERNEL_TYPE_ABS: - kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_abs; + kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_abs_host; kernel_pipeline->kernel_name = "TXE_ABS"; flag = true; break; case GGML_TSAVORITE_KERNEL_TYPE_SIN: - kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_sin; + kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_sin_host; kernel_pipeline->kernel_name = "TXE_SIN"; flag = true; break; case GGML_TSAVORITE_KERNEL_TYPE_SIGMOID: - kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_sigmoid; + kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_sigmoid_host; kernel_pipeline->kernel_name = "TXE_SIGMOID"; flag = true; break; case GGML_TSAVORITE_KERNEL_TYPE_SILU: - kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_silu; + kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_silu_host; kernel_pipeline->kernel_name = "TXE_SILU"; flag = true; break; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 31fa312f65da6..1c8b8e29a822e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -174,4 +174,4 @@ target_link_libraries(${LLAMA_TEST_NAME} PRIVATE mtmd) # dummy executable - not installed get_filename_component(TEST_TARGET test-c.c NAME_WE) add_executable(${TEST_TARGET} test-c.c) -target_link_libraries(${TEST_TARGET} PRIVATE llama ${TLIBS}) +target_link_libraries(${TEST_TARGET} PRIVATE ${TLIBS} llama stdc++) diff --git a/tsi-pkg-build.sh b/tsi-pkg-build.sh index 2dd5f048871b7..488d98abb035b 100755 --- a/tsi-pkg-build.sh +++ b/tsi-pkg-build.sh @@ -6,12 +6,14 @@ echo 'updating submodule' git submodule update --recursive --init cd ggml-tsi-kernel/ module load tsi4 gcc/13.3.0 +export MLIR_SDK_VERSION=/proj/rel/sw/sdk-r.0.1.3 echo 'creating python virtual env' +/proj/local/Python-3.10.12/bin/python3 -m venv blob-creation python3 -m venv blob-creation source blob-creation/bin/activate echo 'installing mlir and python dependencies' -pip install -r /proj/rel/sw/mlir-compiler/python/requirements-common.txt -pip install /proj/rel/sw/mlir-compiler/python/mlir_external_packages-1.2.1-py3-none-any.whl +pip install -r ${MLIR_SDK_VERSION}/compiler/python/requirements-common.txt +pip install ${MLIR_SDK_VERSION}/compiler/python/mlir_external_packages-1.3.0-py3-none-any.whl pip install onnxruntime-training #build TSI kernels for the Tsavorite backend @@ -31,7 +33,6 @@ cd ../posix-kernel/ cd ../../ -export MLIR_SDK_VERSION=/proj/work/rel/sw/sdk-r.0.1.2 #Compile for posix with build-posix as a target folder echo 'building llama.cp, ggml for tsavorite and other binary for posix'