Skip to content

Commit c727c40

Browse files
authored
Merge branch 'master' into torchscript_extensions
2 parents 8fdf44d + 247c4e5 commit c727c40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1665
-1051
lines changed

docs/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ The RedisAI Script data structure is managed via a set of dedicated commands, si
304304

305305
* Created with the [`AI.SCRIPTSET` command](commands.md#aiscriptset)
306306
* Run with the [`AI.SCRIPTRUN` command](commands.md#aiscriptrun)
307-
* Deleted with the [`AI.SCRIPTSEL` command](commands.md#aiscriptdel)
307+
* Deleted with the [`AI.SCRIPTDEL` command](commands.md#aiscriptdel)
308308

309309
We can create a RedisAI Script that performs the same computation as the 'graph.pb' model. The script can look like this:
310310

src/CMakeLists.txt

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ if (CMAKE_BUILD_TYPE STREQUAL Debug)
22
SET(DEBUG_SRC "${CMAKE_CURRENT_SOURCE_DIR}/../opt/readies/cetara/diag/gdb.c")
33
endif()
44

5+
file (GLOB_RECURSE SERIALIZATION_SRC
6+
tensor.c
7+
model.c
8+
script.c
9+
backends.c
10+
stats.c
11+
config.c
12+
serialization/*.c)
13+
14+
file (GLOB BACKEND_COMMON_SRC
15+
backends/util.c
16+
err.c
17+
util/dict.c
18+
tensor.c
19+
serialization/ai_datatypes.c)
20+
521
ADD_LIBRARY(redisai_obj OBJECT
622
util/dict.c
723
util/queue.c
@@ -27,42 +43,38 @@ ADD_LIBRARY(redisai_obj OBJECT
2743
rmutil/heap.c
2844
rmutil/priority_queue.c
2945
rmutil/vector.c run_info.c
46+
redis_ai_types/model_type.c
47+
redis_ai_types/tensor_type.c
48+
redis_ai_types/script_type.c
49+
${SERIALIZATION_SRC}
3050
${DEBUG_SRC})
3151

3252
IF(BUILD_TF)
3353
ADD_LIBRARY(redisai_tensorflow_obj OBJECT
3454
backends/tensorflow.c
35-
backends/util.c
36-
err.c
37-
util/dict.c
38-
tensor.c)
55+
${BACKEND_COMMON_SRC}
56+
)
3957
ENDIF()
4058

4159
IF(BUILD_TFLITE)
4260
ADD_LIBRARY(redisai_tflite_obj OBJECT
4361
backends/tflite.c
44-
backends/util.c
45-
err.c
46-
util/dict.c
47-
tensor.c)
62+
${BACKEND_COMMON_SRC}
63+
)
4864
ENDIF()
4965

5066
IF(BUILD_TORCH)
5167
ADD_LIBRARY(redisai_torch_obj OBJECT
5268
backends/torch.c
53-
backends/util.c
54-
err.c
55-
util/dict.c
56-
tensor.c)
69+
${BACKEND_COMMON_SRC}
70+
)
5771
ENDIF()
5872

5973
IF(BUILD_ORT)
6074
ADD_LIBRARY(redisai_onnxruntime_obj OBJECT
6175
backends/onnxruntime.c
62-
backends/util.c
63-
err.c
64-
util/dict.c
65-
tensor.c)
76+
${BACKEND_COMMON_SRC}
77+
)
6678
ENDIF()
6779

6880
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

src/DAG/dag.c

Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -47,52 +47,6 @@
4747
#include "dag_parser.h"
4848
#include "util/string_utils.h"
4949

50-
/**
51-
* Execution of a TENSORSET DAG step.
52-
* If an error occurs, it is recorded in the DagOp struct.
53-
*
54-
* @param rinfo context in which RedisAI blocking commands operate.
55-
* @param currentOp TENSORSET DagOp to be executed
56-
* @return
57-
*/
58-
void RedisAI_DagRunSession_TensorSet_Step(RedisAI_RunInfo *rinfo, RAI_DagOp *currentOp) {
59-
RAI_Tensor *t = NULL;
60-
const int parse_result =
61-
RAI_parseTensorSetArgs(NULL, currentOp->argv, currentOp->argc, &t, 0, currentOp->err);
62-
if (parse_result > 0) {
63-
RedisModuleString *key_string = currentOp->outkeys[0];
64-
RAI_ContextWriteLock(rinfo);
65-
AI_dictReplace(rinfo->dagTensorsContext, (void *)key_string, t);
66-
RAI_ContextUnlock(rinfo);
67-
currentOp->result = REDISMODULE_OK;
68-
} else {
69-
currentOp->result = REDISMODULE_ERR;
70-
}
71-
}
72-
73-
/**
74-
* Execution of a TENSORGET DAG step.
75-
* If an error occurs, it is recorded in the DagOp struct.
76-
*
77-
* @param rinfo context in which RedisAI blocking commands operate.
78-
* @param currentOp TENSORGET DagOp to be executed
79-
* @return
80-
*/
81-
void RedisAI_DagRunSession_TensorGet_Step(RedisAI_RunInfo *rinfo, RAI_DagOp *currentOp) {
82-
RedisModuleString *key_string = currentOp->inkeys[0];
83-
RAI_Tensor *t = NULL;
84-
RAI_ContextReadLock(rinfo);
85-
currentOp->result = RAI_getTensorFromLocalContext(NULL, rinfo->dagTensorsContext, key_string,
86-
&t, currentOp->err);
87-
RAI_ContextUnlock(rinfo);
88-
if (currentOp->result == REDISMODULE_OK) {
89-
RAI_Tensor *outTensor = NULL;
90-
// TODO: check tensor copy return value
91-
RAI_TensorDeepCopy(t, &outTensor);
92-
currentOp->outTensors = array_append(currentOp->outTensors, outTensor);
93-
}
94-
}
95-
9650
static void Dag_LoadInputsToModelRunCtx(RedisAI_RunInfo *rinfo, RAI_DagOp *currentOp) {
9751
uint n_inkeys = array_len(currentOp->inkeys);
9852
uint n_outkeys = array_len(currentOp->outkeys);
@@ -477,11 +431,13 @@ void RedisAI_DagRunSessionStep(RedisAI_RunInfo *rinfo, const char *devicestr) {
477431

478432
switch (currentOp->commandType) {
479433
case REDISAI_DAG_CMD_TENSORSET: {
480-
RedisAI_DagRunSession_TensorSet_Step(rinfo, currentOp);
434+
// TENSORSET op is done in parsing stage (consider removing it from dag ops).
435+
currentOp->result = REDISMODULE_OK;
481436
break;
482437
}
483438
case REDISAI_DAG_CMD_TENSORGET: {
484-
RedisAI_DagRunSession_TensorGet_Step(rinfo, currentOp);
439+
// TENSORSET op is done when we finish (consider removing it from dag ops).
440+
currentOp->result = REDISMODULE_OK;
485441
break;
486442
}
487443
case REDISAI_DAG_CMD_MODELRUN: {
@@ -680,18 +636,14 @@ int RedisAI_DagRun_Reply(RedisModuleCtx *ctx, RedisModuleString **argv, int argc
680636

681637
case REDISAI_DAG_CMD_TENSORGET: {
682638
rinfo->dagReplyLength++;
683-
if (currentOp->result == REDISMODULE_ERR) {
639+
RAI_Tensor *t;
640+
int res = RAI_getTensorFromLocalContext(NULL, rinfo->dagTensorsContext,
641+
currentOp->inkeys[0], &t, currentOp->err);
642+
if (res != REDISMODULE_OK) {
684643
RedisModule_ReplyWithError(ctx, currentOp->err->detail_oneline);
685644
dag_error = 1;
686645
} else {
687-
if (array_len(currentOp->outTensors) > 0) {
688-
RAI_Tensor *tensor = currentOp->outTensors[0];
689-
RAI_parseTensorGetArgs(ctx, currentOp->argv, currentOp->argc, tensor);
690-
} else if (currentOp->result == -1) {
691-
RedisModule_ReplyWithSimpleString(ctx, "NA");
692-
} else {
693-
RedisModule_ReplyWithError(ctx, "ERR error getting tensor from local context");
694-
}
646+
ReplyWithTensor(ctx, currentOp->fmt, t);
695647
}
696648
break;
697649
}

0 commit comments

Comments
 (0)