Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ 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()
endif()

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()
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion ggml-tsi-kernel
20 changes: 10 additions & 10 deletions ggml/include/ggml-tsavorite.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions ggml/src/ggml-tsavorite/ggml-tsavorite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,55 +389,55 @@ 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;
case GGML_TSAVORITE_KERNEL_TYPE_MULT:
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;
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
7 changes: 4 additions & 3 deletions tsi-pkg-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down