Skip to content

Commit 55bdfbf

Browse files
authored
Merge branch 'master' into Turn_DAG_local_context_into_array
2 parents 2fabf5e + 812444a commit 55bdfbf

File tree

10 files changed

+40
-53
lines changed

10 files changed

+40
-53
lines changed

src/DAG/dag_builder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int RAI_DAGAddRunOp(RAI_DAGRunCtx *run_info, RAI_DAGRunOp *DAGop, RAI_Error *err
112112
return REDISMODULE_OK;
113113
}
114114

115-
int RAI_DAGAddTensorGet(RAI_DAGRunCtx *run_info, const char *t_name, RAI_Error *err) {
115+
int RAI_DAGAddTensorGet(RAI_DAGRunCtx *run_info, const char *t_name) {
116116

117117
RedisAI_RunInfo *rinfo = (RedisAI_RunInfo *)run_info;
118118
RAI_DagOp *op;

src/DAG/dag_builder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int RAI_DAGAddTensorSet(RAI_DAGRunCtx *run_info, const char *t_name, RAI_Tensor
6464
* @param runInfo The DAG to append this op into.
6565
* @param tensor The tensor to set.
6666
*/
67-
int RAI_DAGAddTensorGet(RAI_DAGRunCtx *run_info, const char *t_name, RAI_Error *err);
67+
int RAI_DAGAddTensorGet(RAI_DAGRunCtx *run_info, const char *t_name);
6868

6969
/**
7070
* @brief Add ops to a DAG from string (according to the command syntax). In case of a valid

src/command_parser.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ static int _ModelRunCommand_ParseArgs(RedisModuleCtx *ctx, int argc, RedisModule
2828
return REDISMODULE_ERR;
2929
}
3030
size_t argpos = 1;
31-
RedisModuleKey *modelKey;
32-
const int status =
33-
RAI_GetModelFromKeyspace(ctx, argv[argpos], &modelKey, model, REDISMODULE_READ, error);
31+
const int status = RAI_GetModelFromKeyspace(ctx, argv[argpos], model, REDISMODULE_READ, error);
3432
if (status == REDISMODULE_ERR) {
3533
return REDISMODULE_ERR;
3634
}
@@ -172,9 +170,8 @@ static int _ScriptRunCommand_ParseArgs(RedisModuleCtx *ctx, RedisModuleString **
172170
return REDISMODULE_ERR;
173171
}
174172
size_t argpos = 1;
175-
RedisModuleKey *scriptKey;
176173
const int status =
177-
RAI_GetScriptFromKeyspace(ctx, argv[argpos], &scriptKey, script, REDISMODULE_READ, error);
174+
RAI_GetScriptFromKeyspace(ctx, argv[argpos], script, REDISMODULE_READ, error);
178175
if (status == REDISMODULE_ERR) {
179176
return REDISMODULE_ERR;
180177
}

src/model.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@
2525
/* Return REDISMODULE_ERR if there was an error getting the Model.
2626
* Return REDISMODULE_OK if the model value stored at key was correctly
2727
* returned and available at *model variable. */
28-
int RAI_GetModelFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RedisModuleKey **key,
29-
RAI_Model **model, int mode, RAI_Error *err) {
30-
*key = RedisModule_OpenKey(ctx, keyName, mode);
31-
if (RedisModule_KeyType(*key) == REDISMODULE_KEYTYPE_EMPTY) {
32-
RedisModule_CloseKey(*key);
28+
int RAI_GetModelFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RAI_Model **model,
29+
int mode, RAI_Error *err) {
30+
RedisModuleKey *key = RedisModule_OpenKey(ctx, keyName, mode);
31+
if (RedisModule_KeyType(key) == REDISMODULE_KEYTYPE_EMPTY) {
32+
RedisModule_CloseKey(key);
3333
RAI_SetError(err, RAI_EMODELRUN, "ERR model key is empty");
3434
return REDISMODULE_ERR;
3535
}
36-
if (RedisModule_ModuleTypeGetType(*key) != RedisAI_ModelType) {
37-
RedisModule_CloseKey(*key);
36+
if (RedisModule_ModuleTypeGetType(key) != RedisAI_ModelType) {
37+
RedisModule_CloseKey(key);
3838
RAI_SetError(err, RAI_EMODELRUN, REDISMODULE_ERRORMSG_WRONGTYPE);
3939
return REDISMODULE_ERR;
4040
}
41-
*model = RedisModule_ModuleTypeGetValue(*key);
42-
RedisModule_CloseKey(*key);
41+
*model = RedisModule_ModuleTypeGetValue(key);
42+
RedisModule_CloseKey(key);
4343
return REDISMODULE_OK;
4444
}
4545

src/model.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,15 @@ int RAI_ModelSerialize(RAI_Model *model, char **buffer, size_t *len, RAI_Error *
112112
*
113113
* @param ctx Context in which Redis modules operate
114114
* @param keyName key name
115-
* @param key models's key handle. On success it contains an handle representing
116-
* a Redis key with the requested access mode
117115
* @param model destination model structure
118116
* @param mode key access mode
119117
* @param error contains the error in case of problem with retrival
120118
* @return REDISMODULE_OK if the model value stored at key was correctly
121119
* returned and available at *model variable, or REDISMODULE_ERR if there was
122120
* an error getting the Model
123121
*/
124-
int RAI_GetModelFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RedisModuleKey **key,
125-
RAI_Model **model, int mode, RAI_Error *err);
122+
int RAI_GetModelFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RAI_Model **model,
123+
int mode, RAI_Error *err);
126124

127125
/**
128126
* When a module command is called in order to obtain the position of

src/redisai.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,7 @@ int RedisAI_ModelGet_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
423423

424424
RAI_Error err = {0};
425425
RAI_Model *mto;
426-
RedisModuleKey *key;
427-
const int status = RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto, REDISMODULE_READ, &err);
426+
const int status = RAI_GetModelFromKeyspace(ctx, argv[1], &mto, REDISMODULE_READ, &err);
428427
if (status == REDISMODULE_ERR) {
429428
RedisModule_ReplyWithError(ctx, RAI_GetErrorOneLine(&err));
430429
RAI_ClearError(&err);
@@ -524,17 +523,16 @@ int RedisAI_ModelDel_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
524523
return RedisModule_WrongArity(ctx);
525524

526525
RAI_Model *mto;
527-
RedisModuleKey *key;
528526
RAI_Error err = {0};
529-
const int status = RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto,
530-
REDISMODULE_READ | REDISMODULE_WRITE, &err);
527+
const int status =
528+
RAI_GetModelFromKeyspace(ctx, argv[1], &mto, REDISMODULE_READ | REDISMODULE_WRITE, &err);
531529
if (status == REDISMODULE_ERR) {
532530
RedisModule_ReplyWithError(ctx, RAI_GetErrorOneLine(&err));
533531
RAI_ClearError(&err);
534532
return REDISMODULE_ERR;
535533
}
536534

537-
key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_WRITE);
535+
RedisModuleKey *key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_WRITE);
538536
RedisModule_DeleteKey(key);
539537
RedisModule_CloseKey(key);
540538
RedisModule_ReplicateVerbatim(ctx);
@@ -608,9 +606,8 @@ int RedisAI_ScriptGet_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv
608606
return RedisModule_WrongArity(ctx);
609607

610608
RAI_Script *sto;
611-
RedisModuleKey *key;
612609
RAI_Error err = {0};
613-
const int status = RAI_GetScriptFromKeyspace(ctx, argv[1], &key, &sto, REDISMODULE_READ, &err);
610+
const int status = RAI_GetScriptFromKeyspace(ctx, argv[1], &sto, REDISMODULE_READ, &err);
614611
if (status == REDISMODULE_ERR) {
615612
RedisModule_ReplyWithError(ctx, RAI_GetErrorOneLine(&err));
616613
RAI_ClearError(&err);
@@ -659,15 +656,14 @@ int RedisAI_ScriptDel_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv
659656
return RedisModule_WrongArity(ctx);
660657

661658
RAI_Script *sto;
662-
RedisModuleKey *key;
663659
RAI_Error err = {0};
664-
const int status = RAI_GetScriptFromKeyspace(ctx, argv[1], &key, &sto, REDISMODULE_WRITE, &err);
660+
const int status = RAI_GetScriptFromKeyspace(ctx, argv[1], &sto, REDISMODULE_WRITE, &err);
665661
if (status == REDISMODULE_ERR) {
666662
RedisModule_ReplyWithError(ctx, RAI_GetErrorOneLine(&err));
667663
RAI_ClearError(&err);
668664
return REDISMODULE_ERR;
669665
}
670-
key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_WRITE);
666+
RedisModuleKey *key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_WRITE);
671667
RedisModule_DeleteKey(key);
672668
RedisModule_CloseKey(key);
673669

src/redisai.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ REDISAI_API void MODULE_API_FUNC(RedisAI_ModelFree)(RAI_Model *model, RAI_Error
107107
REDISAI_API RAI_ModelRunCtx *MODULE_API_FUNC(RedisAI_ModelRunCtxCreate)(RAI_Model *model);
108108
REDISAI_API int MODULE_API_FUNC(RedisAI_GetModelFromKeyspace)(RedisModuleCtx *ctx,
109109
RedisModuleString *keyName,
110-
RedisModuleKey **key,
111110
RAI_Model **model, int mode,
112111
RAI_Error *err);
113112
REDISAI_API int MODULE_API_FUNC(RedisAI_ModelRunCtxAddInput)(RAI_ModelRunCtx *mctx,
@@ -136,7 +135,6 @@ REDISAI_API RAI_Script *MODULE_API_FUNC(RedisAI_ScriptCreate)(char *devicestr, c
136135
RAI_Error *err);
137136
REDISAI_API int MODULE_API_FUNC(RedisAI_GetScriptFromKeyspace)(RedisModuleCtx *ctx,
138137
RedisModuleString *keyName,
139-
RedisModuleKey **key,
140138
RAI_Script **script, int mode,
141139
RAI_Error *err);
142140
REDISAI_API void MODULE_API_FUNC(RedisAI_ScriptFree)(RAI_Script *script, RAI_Error *err);
@@ -175,7 +173,7 @@ REDISAI_API int MODULE_API_FUNC(RedisAI_DAGLoadTensor)(RAI_DAGRunCtx *run_info,
175173
REDISAI_API int MODULE_API_FUNC(RedisAI_DAGAddTensorSet)(RAI_DAGRunCtx *run_info,
176174
const char *t_name, RAI_Tensor *tensor);
177175
REDISAI_API int MODULE_API_FUNC(RedisAI_DAGAddTensorGet)(RAI_DAGRunCtx *run_info,
178-
const char *t_name, RAI_Error *err);
176+
const char *t_name);
179177
REDISAI_API int MODULE_API_FUNC(RedisAI_DAGAddOpsFromString)(RAI_DAGRunCtx *run_info,
180178
const char *dag, RAI_Error *err);
181179
REDISAI_API size_t MODULE_API_FUNC(RedisAI_DAGNumOps)(RAI_DAGRunCtx *run_info);

src/script.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,21 @@ RAI_Script *RAI_ScriptGetShallowCopy(RAI_Script *script) {
154154
/* Return REDISMODULE_ERR if there was an error getting the Script.
155155
* Return REDISMODULE_OK if the model value stored at key was correctly
156156
* returned and available at *model variable. */
157-
int RAI_GetScriptFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RedisModuleKey **key,
158-
RAI_Script **script, int mode, RAI_Error *err) {
159-
*key = RedisModule_OpenKey(ctx, keyName, mode);
160-
if (RedisModule_KeyType(*key) == REDISMODULE_KEYTYPE_EMPTY) {
161-
RedisModule_CloseKey(*key);
157+
int RAI_GetScriptFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RAI_Script **script,
158+
int mode, RAI_Error *err) {
159+
RedisModuleKey *key = RedisModule_OpenKey(ctx, keyName, mode);
160+
if (RedisModule_KeyType(key) == REDISMODULE_KEYTYPE_EMPTY) {
161+
RedisModule_CloseKey(key);
162162
RAI_SetError(err, RAI_ESCRIPTRUN, "ERR script key is empty");
163163
return REDISMODULE_ERR;
164164
}
165-
if (RedisModule_ModuleTypeGetType(*key) != RedisAI_ScriptType) {
166-
RedisModule_CloseKey(*key);
165+
if (RedisModule_ModuleTypeGetType(key) != RedisAI_ScriptType) {
166+
RedisModule_CloseKey(key);
167167
RAI_SetError(err, RAI_ESCRIPTRUN, REDISMODULE_ERRORMSG_WRONGTYPE);
168168
return REDISMODULE_ERR;
169169
}
170-
*script = RedisModule_ModuleTypeGetValue(*key);
171-
RedisModule_CloseKey(*key);
170+
*script = RedisModule_ModuleTypeGetValue(key);
171+
RedisModule_CloseKey(key);
172172
return REDISMODULE_OK;
173173
}
174174

src/script.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,14 @@ RAI_Script *RAI_ScriptGetShallowCopy(RAI_Script *script);
153153
*
154154
* @param ctx Context in which Redis modules operate
155155
* @param keyName key name
156-
* @param key script's key handle. On success it contains an handle representing
157-
* a Redis key with the requested access mode
158156
* @param script destination script structure
159157
* @param mode key access mode
160158
* @return REDISMODULE_OK if the script value stored at key was correctly
161159
* returned and available at *script variable, or REDISMODULE_ERR if there was
162160
* an error getting the Script
163161
*/
164-
int RAI_GetScriptFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RedisModuleKey **key,
165-
RAI_Script **script, int mode, RAI_Error *err);
162+
int RAI_GetScriptFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RAI_Script **script,
163+
int mode, RAI_Error *err);
166164

167165
/**
168166
* When a module command is called in order to obtain the position of

tests/module/DAG_utils.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ int testKeysMismatchError(RedisModuleCtx *ctx) {
157157
RAI_Tensor *t = (RAI_Tensor *)_getFromKeySpace(ctx, "a{1}");
158158
RedisAI_DAGLoadTensor(run_info, "input", t);
159159

160-
RedisAI_DAGAddTensorGet(run_info, "non existing tensor", err);
160+
RedisAI_DAGAddTensorGet(run_info, "non existing tensor");
161161
int status = RedisAI_DAGRun(run_info, _DAGFinishFuncError, NULL, err);
162162
if(!_assertError(err, status, "ERR INPUT key cannot be found in DAG")) {
163163
goto cleanup;
@@ -203,7 +203,7 @@ int testBuildDAGFromString(RedisModuleCtx *ctx) {
203203
goto cleanup;
204204
}
205205
RedisModule_Assert(RedisAI_DAGNumOps(run_info) == 3);
206-
RedisAI_DAGAddTensorGet(run_info, "input1", results.error);
206+
RedisAI_DAGAddTensorGet(run_info, "input1");
207207
RedisModule_Assert(RedisAI_DAGNumOps(run_info) == 4);
208208

209209
pthread_mutex_lock(&global_lock);
@@ -247,7 +247,7 @@ int testSimpleDAGRun(RedisModuleCtx *ctx) {
247247
goto cleanup;
248248
}
249249

250-
RedisAI_DAGAddTensorGet(run_info, "output", results.error);
250+
RedisAI_DAGAddTensorGet(run_info, "output");
251251
pthread_mutex_lock(&global_lock);
252252
if (RedisAI_DAGRun(run_info, _DAGFinishFunc, &results, results.error) != REDISMODULE_OK) {
253253
pthread_mutex_unlock(&global_lock);
@@ -300,7 +300,7 @@ int testSimpleDAGRun2(RedisModuleCtx *ctx) {
300300
goto cleanup;
301301
}
302302

303-
RedisAI_DAGAddTensorGet(run_info, "output", results.error);
303+
RedisAI_DAGAddTensorGet(run_info, "output");
304304
pthread_mutex_lock(&global_lock);
305305
if (RedisAI_DAGRun(run_info, _DAGFinishFunc, &results, results.error) != REDISMODULE_OK) {
306306
pthread_mutex_unlock(&global_lock);
@@ -350,7 +350,7 @@ int testSimpleDAGRun2Error(RedisModuleCtx *ctx) {
350350
goto cleanup;
351351
}
352352

353-
RedisAI_DAGAddTensorGet(run_info, "output", results.error);
353+
RedisAI_DAGAddTensorGet(run_info, "output");
354354
pthread_mutex_lock(&global_lock);
355355
if (RedisAI_DAGRun(run_info, _DAGFinishFunc, &results, results.error) != REDISMODULE_OK) {
356356
pthread_mutex_unlock(&global_lock);
@@ -412,7 +412,7 @@ int testDAGResnet(RedisModuleCtx *ctx) {
412412
RedisAI_DAGRunOpAddOutput(script_op, "output:{{1}}");
413413
RedisAI_DAGAddRunOp(run_info, script_op, results.error);
414414

415-
RedisAI_DAGAddTensorGet(run_info, "output:{{1}}", results.error);
415+
RedisAI_DAGAddTensorGet(run_info, "output:{{1}}");
416416

417417
pthread_mutex_lock(&global_lock);
418418
if (RedisAI_DAGRun(run_info, _DAGFinishFunc, &results, results.error) != REDISMODULE_OK) {

0 commit comments

Comments
 (0)