Skip to content
Open
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
85 changes: 76 additions & 9 deletions examples/simple/simple-backend-tsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ float test_input_1[GGML_TSAVORITE_KERNEL_TYPE_COUNT][NUM_ELEMENTS] = {
//ABS Kernel
{1.1, -4.4, 10, -5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, -23, 24, 25, -26, 27, -28, 29, -30, 31, -32.6},
//SIN Kernel
{1.1, 4.4, 10, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 20, 20, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32.6}

{1.1, 4.4, 10, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 20, 20, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32.6},
//SGN Kernel
{-5, -3, -1, 0, 1, 2, 3, 10, -7, 8, -9, 0, 4, -2, 6, -6, 15, -15, 20, -20, 25, -25, 30, -30, 100, -100, 50, -50, 7, -8, 9, -10}
};
float test_input_2[GGML_TSAVORITE_KERNEL_TYPE_COUNT][NUM_ELEMENTS] = {
//ADD KERNEL
Expand All @@ -60,7 +61,9 @@ float test_input_2[GGML_TSAVORITE_KERNEL_TYPE_COUNT][NUM_ELEMENTS] = {
//ABS KERNEL input not used
{1.1, 2.2, 5, 10, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32},
//SIN Kernel input not used
{1.1, 2.2, 5, 10, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}
{1.1, 2.2, 5, 10, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32},
//SGN Kernel
{-5, -3, -1, 0, 1, 2, 3, 10, -7, 8, -9, 0, 4, -2, 6, -6, 15, -15, 20, -20, 25, -25, 30, -30, 100, -100, 50, -50, 7, -8, 9, -10}
};

float test_result[GGML_TSAVORITE_KERNEL_TYPE_COUNT][NUM_ELEMENTS] = {
Expand All @@ -81,8 +84,9 @@ float test_result[GGML_TSAVORITE_KERNEL_TYPE_COUNT][NUM_ELEMENTS] = {
//ABS Kernel
{1.1, 4.4, 10, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32.6},
//SIN Kernel
{0.891207, -0.951602, -0.544021, -0.958924, -0.958924, -0.279416, 0.656987, 0.989358, 0.412118, -0.544021, -0.999990, -0.536573, 0.420167, 0.990607, 0.650288, -0.287903, -0.961398, -0.750987, 0.149877, 0.912945, 0.912945, 0.912945, -0.846220, -0.905578, -0.132352, 0.762559, 0.956376, 0.270906, -0.663634, -0.988032, -0.404039, 0.926149}

{0.891207, -0.951602, -0.544021, -0.958924, -0.958924, -0.279416, 0.656987, 0.989358, 0.412118, -0.544021, -0.999990, -0.536573, 0.420167, 0.990607, 0.650288, -0.287903, -0.961398, -0.750987, 0.149877, 0.912945, 0.912945, 0.912945, -0.846220, -0.905578, -0.132352, 0.762559, 0.956376, 0.270906, -0.663634, -0.988032, -0.404039, 0.926149},
//SGN Kernel
{-1, -1, -1, 0, 1, 1, 1, 1, -1, 1, -1, 0, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the results always -1 or 1 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes ashish, signum function have -1, 0, or 1.

};

float test_input_scale_1[GGML_TSAVORITE_KERNEL_TYPE_COUNT][NUM_ELEMENTS_SCALE] = {
Expand Down Expand Up @@ -139,7 +143,26 @@ float test_input_scale_1[GGML_TSAVORITE_KERNEL_TYPE_COUNT][NUM_ELEMENTS_SCALE] =
-9, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-16, 25, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
//SGN KERNEL
{
-5.3, -4.8, -4.2, -3.9, -3.5, -3.2, -3.0, -2.8, -2.6, -2.4,
-2.2, -2.0, -1.9, -1.7, -1.5, -1.3, -1.1, -1.0, -0.8, -0.6,
-0.5, -0.3, -0.1, 0.0, 0.1, 0.3, 0.5, 0.6, 0.8, 1.0,
1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0,
3.2, 3.4, 3.6, 3.8, 4.0, 4.2, 4.4, 4.6, 4.8, 5.0,
-6.1, -6.0, -5.8, -5.6, -5.4, -5.2, -5.0, -4.9, -4.7, -4.5,
-4.3, -4.1, -3.7, -3.4, -3.1, -2.7, -2.5, -2.3, -2.1, -1.8,
-1.4, -1.2, -1.0, -0.7, -0.4, -0.2, 0.2, 0.4, 0.7, 1.1,
1.3, 1.5, 1.7, 1.9, 2.1, 2.3, 2.5, 2.7, 2.9, 3.1,
3.3, 3.5, 3.7, 3.9, 4.1, 4.3, 4.5, 4.7, 4.9, 5.1,
-7.5, -7.2, -6.9, -6.6, -6.3, -6.0, -5.7, -5.4, -5.1, -4.8,
-4.5, -4.2, -3.9, -3.6, -3.3, -3.0, -2.7, -2.4, -2.1, -1.8,
-1.5, -1.2, -0.9, -0.6, -0.3, 0.0, 0.3, 0.6, 0.9, 1.2,
1.5, 1.8, 2.1, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.2,
4.5, 4.8, 5.1, 5.4, 5.7, 6.0, 6.3, 6.6, 6.9, 7.2,
7.5, 7.8, 8.0
}
};

float test_input_scale_2[GGML_TSAVORITE_KERNEL_TYPE_COUNT][NUM_ELEMENTS_SCALE] = {
Expand Down Expand Up @@ -197,7 +220,26 @@ float test_input_scale_2[GGML_TSAVORITE_KERNEL_TYPE_COUNT][NUM_ELEMENTS_SCALE] =
-9, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-16, 25, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
//SGN KERNEL
{
-5.3, -4.8, -4.2, -3.9, -3.5, -3.2, -3.0, -2.8, -2.6, -2.4,
-2.2, -2.0, -1.9, -1.7, -1.5, -1.3, -1.1, -1.0, -0.8, -0.6,
-0.5, -0.3, -0.1, 0.0, 0.1, 0.3, 0.5, 0.6, 0.8, 1.0,
1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0,
3.2, 3.4, 3.6, 3.8, 4.0, 4.2, 4.4, 4.6, 4.8, 5.0,
-6.1, -6.0, -5.8, -5.6, -5.4, -5.2, -5.0, -4.9, -4.7, -4.5,
-4.3, -4.1, -3.7, -3.4, -3.1, -2.7, -2.5, -2.3, -2.1, -1.8,
-1.4, -1.2, -1.0, -0.7, -0.4, -0.2, 0.2, 0.4, 0.7, 1.1,
1.3, 1.5, 1.7, 1.9, 2.1, 2.3, 2.5, 2.7, 2.9, 3.1,
3.3, 3.5, 3.7, 3.9, 4.1, 4.3, 4.5, 4.7, 4.9, 5.1,
-7.5, -7.2, -6.9, -6.6, -6.3, -6.0, -5.7, -5.4, -5.1, -4.8,
-4.5, -4.2, -3.9, -3.6, -3.3, -3.0, -2.7, -2.4, -2.1, -1.8,
-1.5, -1.2, -0.9, -0.6, -0.3, 0.0, 0.3, 0.6, 0.9, 1.2,
1.5, 1.8, 2.1, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.2,
4.5, 4.8, 5.1, 5.4, 5.7, 6.0, 6.3, 6.6, 6.9, 7.2,
7.5, 7.8, 8.0
}
};
float test_result_scale[GGML_TSAVORITE_KERNEL_TYPE_COUNT][NUM_ELEMENTS_SCALE] = {
// ADD KERNEL
Expand Down Expand Up @@ -263,7 +305,26 @@ float test_result_scale[GGML_TSAVORITE_KERNEL_TYPE_COUNT][NUM_ELEMENTS_SCALE] =
0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471,
-0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471,
0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471, 0.841471,
0.841471, 0.841471, 0.841471}
0.841471, 0.841471, 0.841471},
//SGN KERNEL
{
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1, 0, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1
}
};

// This is a simple model with two tensors a and b
Expand Down Expand Up @@ -436,6 +497,9 @@ static struct ggml_cgraph * build_graph(const simple_model& model, enum ggml_tsa
case GGML_TSAVORITE_KERNEL_TYPE_SIN:
result = ggml_sin(ctx0, model.a);
break;
case GGML_TSAVORITE_KERNEL_TYPE_SGN:
result = ggml_sgn(ctx0, model.a);
break;
default:
ggml_free(ctx0);
fprintf(stderr, "\n Non Supported Operation \n");
Expand Down Expand Up @@ -488,6 +552,8 @@ enum ggml_tsavorite_kernel_type convert_testcase_to_ops_type (const char *testCa
return GGML_TSAVORITE_KERNEL_TYPE_ABS;
else if (!strcmp(testCase,"sin"))
return GGML_TSAVORITE_KERNEL_TYPE_SIN;
else if (!strcmp(testCase,"sgn"))
return GGML_TSAVORITE_KERNEL_TYPE_SGN;

fprintf(stderr, "\n un-supported test case %s hence running default test case which is add operation \n", testCase);
return GGML_TSAVORITE_KERNEL_TYPE_ADD;
Expand Down Expand Up @@ -549,7 +615,8 @@ int main(int argc, char *argv[]) {
ops_type == GGML_TSAVORITE_KERNEL_TYPE_SQR ||
ops_type == GGML_TSAVORITE_KERNEL_TYPE_NEG ||
ops_type == GGML_TSAVORITE_KERNEL_TYPE_ABS ||
ops_type == GGML_TSAVORITE_KERNEL_TYPE_SIN)
ops_type == GGML_TSAVORITE_KERNEL_TYPE_SIN ||
ops_type == GGML_TSAVORITE_KERNEL_TYPE_SGN)
num_of_input_tensors = NUM_INPUT_URINARY_TENSORS;
else
num_of_input_tensors = NUM_INPUT_TENSORS;
Expand Down
2 changes: 2 additions & 0 deletions ggml/include/ggml-tsavorite.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ enum ggml_tsavorite_kernel_type {
GGML_TSAVORITE_KERNEL_TYPE_NEG,
GGML_TSAVORITE_KERNEL_TYPE_ABS,
GGML_TSAVORITE_KERNEL_TYPE_SIN,
GGML_TSAVORITE_KERNEL_TYPE_SGN,
GGML_TSAVORITE_KERNEL_TYPE_SIGMOID,
GGML_TSAVORITE_KERNEL_TYPE_SILU,

Expand Down Expand Up @@ -161,6 +162,7 @@ extern void _mlir_ciface_txe_sqr_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_sgn_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);
Expand Down
12 changes: 12 additions & 0 deletions ggml/src/ggml-tsavorite/ggml-tsavorite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ static txe_compute_pipeline_state_s tsi_kernel_setup(enum ggml_tsavorite_kernel_
kernel_pipeline->kernel_name = "TXE_SIN";
flag = true;
break;
case GGML_TSAVORITE_KERNEL_TYPE_SGN:
kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_sgn_host;
kernel_pipeline->kernel_name = "TXE_SGN";
flag = true;
break;
case GGML_TSAVORITE_KERNEL_TYPE_SIGMOID:
kernel_pipeline->_mlir_fptr_1_input = &_mlir_ciface_txe_sigmoid_host;
kernel_pipeline->kernel_name = "TXE_SIGMOID";
Expand Down Expand Up @@ -598,6 +603,7 @@ static struct ggml_backend_tsavorite_context *ggml_tsavorite_init(ggml_backend_d
GGML_TSAVORITE_KERNEL(GGML_TSAVORITE_KERNEL_TYPE_NEG, true);
GGML_TSAVORITE_KERNEL(GGML_TSAVORITE_KERNEL_TYPE_ABS, true);
GGML_TSAVORITE_KERNEL(GGML_TSAVORITE_KERNEL_TYPE_SIN, true);
GGML_TSAVORITE_KERNEL(GGML_TSAVORITE_KERNEL_TYPE_SGN, true);
GGML_TSAVORITE_KERNEL(GGML_TSAVORITE_KERNEL_TYPE_SIGMOID, true);
GGML_TSAVORITE_KERNEL(GGML_TSAVORITE_KERNEL_TYPE_SILU, true);
}
Expand Down Expand Up @@ -708,6 +714,7 @@ static bool ggml_tsavorite_supports_op(const struct ggml_backend_tsavorite_devic
case GGML_UNARY_OP_ABS:
case GGML_UNARY_OP_SIGMOID:
case GGML_UNARY_OP_SILU:
case GGML_UNARY_OP_SGN:
break;
default:
return false;
Expand Down Expand Up @@ -876,6 +883,10 @@ static enum ggml_status ggml_tsavorite_graph_compute(ggml_backend_t backend,
kernel_type = GGML_TSAVORITE_KERNEL_TYPE_SILU;
num_of_input_tensors = TSAVORITE_UNARY_INPUT_TENSORS;
break;
case GGML_UNARY_OP_SGN:
kernel_type = GGML_TSAVORITE_KERNEL_TYPE_SGN;
num_of_input_tensors = TSAVORITE_UNARY_INPUT_TENSORS;
break;
default:
ggml_backend_tsavorite_device_rel(
(struct ggml_backend_tsavorite_device_context *)backend->device->context);
Expand Down Expand Up @@ -1842,6 +1853,7 @@ static bool ggml_backend_tsavorite_device_offload_op(ggml_backend_dev_t dev,
case GGML_UNARY_OP_ABS:
case GGML_UNARY_OP_SIGMOID:
case GGML_UNARY_OP_SILU:
case GGML_UNARY_OP_SGN:
break;
default:
return false;
Expand Down
2 changes: 1 addition & 1 deletion tsi-pkg-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fi
cat > ./${TSI_GGML_BUNDLE_INSTALL_DIR}/ggml.sh << EOL
#!/bin/bash
export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:\$(pwd)
tsi_kernels=("add" "sub" "mult" "div" "abs" "inv" "neg" "sin" "sqrt" "sqr" "sigmoid" "silu")
tsi_kernels=("add" "sub" "mult" "div" "abs" "inv" "neg" "sin" "sgn" "sqrt" "sqr" "sigmoid" "silu")

for kernel in "\${tsi_kernels[@]}"; do
mkdir -p ${TSI_BLOB_INSTALL_DIR}/txe_\$kernel
Expand Down