Skip to content

Commit f604387

Browse files
author
DvirDukhan
authored
Merge branch 'master' into macos_build
2 parents bcda35a + f034ebf commit f604387

39 files changed

+640
-318
lines changed

opt/build/docker/dockerfile.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ RUN echo "Building for {{REDIS_OSNICK}} ({{REDIS_OS}}) for {{REDIS_ARCH}} [with
2424
{% include "templates/gpu.yml" %}
2525
{% endif %}
2626

27+
# centos8 specific integration until a move to rocky or similar
28+
{% if REDIS_OSNICK == "centos8" %}
29+
RUN cd /etc/yum.repos.d/
30+
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
31+
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
32+
{% endif %}
33+
2734
WORKDIR /build
2835
COPY --from=redis /usr/local/ /usr/local/
2936

opt/system-setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def common_last(self):
7171
else:
7272
self.run("%s/bin/getcmake" % READIES)
7373

74-
self.pip_install("-r %s/tests/flow/tests_setup/test_requirements.txt" % ROOT)
74+
self.pip_install("--ignore-installed PyYAML -r %s/tests/flow/tests_setup/test_requirements.txt" % ROOT)
7575

7676
self.pip_install("awscli")
7777
self.pip_install("mkdocs mkdocs-material mkdocs-extensions")

src/backends/tensorflow.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ int RAI_InitBackendTF(int (*get_api_fn)(const char *, void *)) {
1515
get_api_fn("RedisModule_Realloc", ((void **)&RedisModule_Realloc));
1616
get_api_fn("RedisModule_Strdup", ((void **)&RedisModule_Strdup));
1717

18+
// Set min logging level to 3 (out of 5) - this is workaround since if TF is writing extensively
19+
// log messages that to stderr, it may cause the system to be stuck.
20+
RedisModule_Assert(putenv("TF_CPP_MIN_LOG_LEVEL=3") == 0);
21+
1822
return REDISMODULE_OK;
1923
}
2024

src/execution/DAG/dag.c

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static void Dag_LoadInputsToCurrentOp(RedisAI_RunInfo *rinfo, RAI_DagOp *current
7272
}
7373

7474
for (uint i = 0; i < n_outkeys; i++) {
75-
RAI_ExecutionCtx_AddOuputPlaceholder(currentOp->ectx);
75+
RAI_ExecutionCtx_AddOutputPlaceholder(currentOp->ectx);
7676
}
7777
}
7878

@@ -260,7 +260,7 @@ void RedisAI_DagRunSession_ScriptRun_Step(RedisAI_RunInfo *rinfo, RAI_DagOp *cur
260260
RAI_ExecutionCtx_AddInput(currentOp->ectx, inputTensors[i]);
261261
}
262262
for (uint i = 0; i < n_outkeys; i++) {
263-
RAI_ExecutionCtx_AddOuputPlaceholder(currentOp->ectx);
263+
RAI_ExecutionCtx_AddOutputPlaceholder(currentOp->ectx);
264264
}
265265
}
266266

@@ -574,44 +574,15 @@ int RedisAI_DagRun_Reply(RedisModuleCtx *ctx, RedisModuleString **argv, int argc
574574
break;
575575
}
576576

577-
case REDISAI_DAG_CMD_MODELRUN: {
578-
rinfo->dagReplyLength++;
579-
struct RedisAI_RunStats *rstats = NULL;
580-
RAI_GetRunStats(currentOp->runkey, &rstats);
581-
if (currentOp->result == REDISMODULE_ERR) {
582-
RAI_SafeAddDataPoint(rstats, 0, 1, 1, 0);
583-
RedisModule_ReplyWithError(ctx, currentOp->err->detail_oneline);
584-
dag_error = 1;
585-
} else if (currentOp->result == -1) {
586-
RedisModule_ReplyWithSimpleString(ctx, "NA");
587-
} else {
588-
RAI_Tensor *t = NULL;
589-
if (RAI_ExecutionCtx_NumOutputs(currentOp->ectx) > 0) {
590-
t = RAI_ExecutionCtx_GetOutput(currentOp->ectx, 0);
591-
}
592-
int batch_size = 0;
593-
if (t) {
594-
batch_size = RAI_TensorDim(t, 0);
595-
}
596-
RAI_SafeAddDataPoint(rstats, currentOp->duration_us, 1, 0, batch_size);
597-
RedisModule_ReplyWithSimpleString(ctx, "OK");
598-
}
599-
break;
600-
}
601-
577+
case REDISAI_DAG_CMD_MODELRUN:
602578
case REDISAI_DAG_CMD_SCRIPTRUN: {
603579
rinfo->dagReplyLength++;
604-
struct RedisAI_RunStats *rstats = NULL;
605-
RAI_GetRunStats(currentOp->runkey, &rstats);
606580
if (currentOp->result == REDISMODULE_ERR) {
607-
RAI_SafeAddDataPoint(rstats, 0, 1, 1, 0);
608581
RedisModule_ReplyWithError(ctx, currentOp->err->detail_oneline);
609582
dag_error = 1;
610583
} else if (currentOp->result == -1) {
611584
RedisModule_ReplyWithSimpleString(ctx, "NA");
612585
} else {
613-
int batch_size = 1;
614-
RAI_SafeAddDataPoint(rstats, currentOp->duration_us, 1, 0, batch_size);
615586
RedisModule_ReplyWithSimpleString(ctx, "OK");
616587
}
617588
break;

src/execution/DAG/dag_builder.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ RAI_DAGRunOp *RAI_DAGCreateModelRunOp(RAI_Model *model) {
6161
op->commandType = REDISAI_DAG_CMD_MODELRUN;
6262
op->ectx = (RAI_ExecutionCtx *)mctx;
6363
op->devicestr = model->devicestr;
64-
op->runkey = RAI_HoldString((RedisModuleString *)model->infokey);
6564
return (RAI_DAGRunOp *)op;
6665
}
6766

@@ -73,7 +72,6 @@ RAI_DAGRunOp *RAI_DAGCreateScriptRunOp(RAI_Script *script, const char *func_name
7372
op->commandType = REDISAI_DAG_CMD_SCRIPTRUN;
7473
op->ectx = (RAI_ExecutionCtx *)sctx;
7574
op->devicestr = script->devicestr;
76-
op->runkey = RAI_HoldString((RedisModuleString *)script->infokey);
7775
return (RAI_DAGRunOp *)op;
7876
}
7977

src/execution/DAG/dag_op.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ int RAI_InitDagOp(RAI_DagOp **result) {
1313
dagOp = (RAI_DagOp *)RedisModule_Calloc(1, sizeof(RAI_DagOp));
1414

1515
dagOp->commandType = REDISAI_DAG_CMD_NONE;
16-
dagOp->runkey = NULL;
1716
dagOp->inkeys = (RedisModuleString **)array_new(RedisModuleString *, 1);
1817
dagOp->outkeys = (RedisModuleString **)array_new(RedisModuleString *, 1);
1918
dagOp->inkeys_indices = array_new(size_t, 1);
@@ -31,13 +30,9 @@ int RAI_InitDagOp(RAI_DagOp **result) {
3130
return REDISMODULE_OK;
3231
}
3332

34-
void RAI_DagOpSetRunKey(RAI_DagOp *dagOp, RedisModuleString *runkey) { dagOp->runkey = runkey; }
35-
3633
void RAI_FreeDagOp(RAI_DagOp *dagOp) {
3734

3835
RAI_FreeError(dagOp->err);
39-
if (dagOp->runkey)
40-
RedisModule_FreeString(NULL, dagOp->runkey);
4136

4237
if (dagOp->outTensor)
4338
RAI_TensorFree(dagOp->outTensor);

src/execution/DAG/dag_op.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ typedef enum DAGCommand {
1818

1919
typedef struct RAI_DagOp {
2020
DAGCommand commandType;
21-
RedisModuleString *runkey;
2221
RedisModuleString **inkeys;
2322
RedisModuleString **outkeys;
2423
size_t *inkeys_indices;
@@ -48,12 +47,3 @@ int RAI_InitDagOp(RAI_DagOp **result);
4847
* @param RAI_DagOp context in which RedisAI command operates.
4948
*/
5049
void RAI_FreeDagOp(RAI_DagOp *dagOp);
51-
52-
/**
53-
* @brief Sets the key name of current dag op execution subject. The subject is either a model or a
54-
* script.
55-
*
56-
* @param dagOp Current op.
57-
* @param runkey Subject key name.
58-
*/
59-
void RAI_DagOpSetRunKey(RAI_DagOp *dagOp, RedisModuleString *runkey);

src/execution/background_workers.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,40 @@ static void _BGThread_Wait(RunQueueInfo *run_queue_info) {
5454
&absTimeout);
5555
}
5656

57+
static void _BGThread_SaveStats(RedisAI_RunInfo *rinfo) {
58+
for (size_t i = 0; i < rinfo->dagOpCount; i++) {
59+
RAI_DagOp *currentOp = rinfo->dagOps[i];
60+
61+
if (currentOp->commandType == REDISAI_DAG_CMD_MODELRUN ||
62+
currentOp->commandType == REDISAI_DAG_CMD_SCRIPTRUN) {
63+
if (currentOp->result == REDISMODULE_ERR) {
64+
RAI_StatsAddDataPoint(RAI_ExecutionCtx_GetStats(currentOp->ectx), 0, 1, 1, 0);
65+
} else if (currentOp->result == REDISMODULE_OK) {
66+
unsigned long batch_size = 1;
67+
if (currentOp->commandType == REDISAI_DAG_CMD_MODELRUN) {
68+
RAI_Tensor *t = NULL;
69+
if (RAI_ExecutionCtx_NumOutputs(currentOp->ectx) > 0) {
70+
t = RAI_ExecutionCtx_GetOutput(currentOp->ectx, 0);
71+
}
72+
if (t) {
73+
batch_size = RAI_TensorDim(t, 0);
74+
} else {
75+
batch_size = 0;
76+
}
77+
}
78+
RAI_StatsAddDataPoint(RAI_ExecutionCtx_GetStats(currentOp->ectx),
79+
currentOp->duration_us, 1, 0, batch_size);
80+
}
81+
}
82+
}
83+
}
84+
5785
static void _BGThread_RinfoFinish(RedisAI_RunInfo *rinfo) {
5886
RedisAI_RunInfo *orig = rinfo->orig_copy;
5987
uint dagRefCount = RAI_DagRunInfoFreeShallowCopy(rinfo);
6088
if (dagRefCount == 0) {
89+
// Save stats for every DAG execute operation.
90+
_BGThread_SaveStats(orig);
6191
RedisAI_OnFinishCtx *finish_ctx = orig;
6292
orig->OnFinish(finish_ctx, orig->private_data);
6393
}

src/execution/execution_contexts/execution_ctx.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
#include "redismodule.h"
33
#include "util/arr.h"
44

5-
void RAI_ExecutionCtx_Init(RAI_ExecutionCtx *ctx, RAI_ExecutionCtx_Free_fn freeFn) {
5+
void RAI_ExecutionCtx_Init(RAI_ExecutionCtx *ctx, RAI_RunStats *run_stats,
6+
RAI_ExecutionCtx_Free_fn freeFn) {
67
ctx->inputs = array_new(RAI_Tensor *, 10);
78
ctx->outputs = array_new(RAI_Tensor *, 10);
9+
ctx->runStats = run_stats;
810
ctx->freeFn = freeFn;
911
}
1012
void RAI_ExecutionCtx_Free(RAI_ExecutionCtx *ctx) {
@@ -21,6 +23,7 @@ void RAI_ExecutionCtx_Free(RAI_ExecutionCtx *ctx) {
2123
}
2224

2325
inline size_t RAI_ExecutionCtx_NumInputs(RAI_ExecutionCtx *ctx) { return array_len(ctx->inputs); }
26+
2427
inline void RAI_ExecutionCtx_AddInput(RAI_ExecutionCtx *ctx, RAI_Tensor *t) {
2528
if (t != NULL) {
2629
t = RAI_TensorGetShallowCopy(t);
@@ -35,7 +38,7 @@ inline RAI_Tensor *RAI_ExecutionCtx_GetInput(RAI_ExecutionCtx *ctx, size_t index
3538

3639
inline size_t RAI_ExecutionCtx_NumOutputs(RAI_ExecutionCtx *ctx) { return array_len(ctx->outputs); }
3740

38-
inline void RAI_ExecutionCtx_AddOuputPlaceholder(RAI_ExecutionCtx *ctx) {
41+
inline void RAI_ExecutionCtx_AddOutputPlaceholder(RAI_ExecutionCtx *ctx) {
3942
ctx->outputs = array_append(ctx->outputs, NULL);
4043
}
4144

@@ -48,3 +51,5 @@ inline RAI_Tensor *RAI_ExecutionCtx_GetOutput(RAI_ExecutionCtx *ctx, size_t inde
4851
RedisModule_Assert(index < array_len(ctx->outputs));
4952
return ctx->outputs[index];
5053
}
54+
55+
inline RAI_RunStats *RAI_ExecutionCtx_GetStats(RAI_ExecutionCtx *ctx) { return ctx->runStats; }

src/execution/execution_contexts/execution_ctx.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <redis_ai_objects/stats.h>
34
#include "redis_ai_objects/tensor.h"
45

56
// Pre decleration
@@ -15,6 +16,7 @@ typedef void (*RAI_ExecutionCtx_Free_fn)(RAI_ExecutionCtx *ctx);
1516
typedef struct RAI_ExecutionCtx {
1617
RAI_Tensor **inputs; // DAG op input tensors.
1718
RAI_Tensor **outputs; // DAG op output tensors.
19+
RAI_RunStats *runStats; // The underline op's (Model/Script) stats entry.
1820
RAI_ExecutionCtx_Free_fn freeFn; // Inheriting execution context free function.
1921
} RAI_ExecutionCtx;
2022

@@ -24,7 +26,8 @@ typedef struct RAI_ExecutionCtx {
2426
* @param ctx - Execution context to initialize.
2527
* @param freeFn - Specific free function for inheriting execution contexts (script or model)
2628
*/
27-
void RAI_ExecutionCtx_Init(RAI_ExecutionCtx *ctx, RAI_ExecutionCtx_Free_fn freeFn);
29+
void RAI_ExecutionCtx_Init(RAI_ExecutionCtx *ctx, RAI_RunStats *run_stats,
30+
RAI_ExecutionCtx_Free_fn freeFn);
2831

2932
/**
3033
* @brief Frees the execution context internal structures. To be used from an inhereting execution
@@ -72,7 +75,7 @@ size_t RAI_ExecutionCtx_NumOutputs(RAI_ExecutionCtx *ctx);
7275
*
7376
* @param ctx - Execution context.
7477
*/
75-
void RAI_ExecutionCtx_AddOuputPlaceholder(RAI_ExecutionCtx *ctx);
78+
void RAI_ExecutionCtx_AddOutputPlaceholder(RAI_ExecutionCtx *ctx);
7679

7780
/**
7881
* @brief Sets an output tensor in a specfic index, populated before by a placeholder.
@@ -91,3 +94,10 @@ void RAI_ExecutionCtx_SetOutput(RAI_ExecutionCtx *ctx, RAI_Tensor *t, size_t ind
9194
* @return RAI_Tensor* - Output tensor.
9295
*/
9396
RAI_Tensor *RAI_ExecutionCtx_GetOutput(RAI_ExecutionCtx *ctx, size_t index);
97+
98+
/**
99+
* @brief Returns the RunStats object for underline object.
100+
* @param ctx - Execution context.
101+
* @return RAI_RunStats
102+
*/
103+
RAI_RunStats *RAI_ExecutionCtx_GetStats(RAI_ExecutionCtx *ctx);

0 commit comments

Comments
 (0)