Skip to content

Commit 24f02b7

Browse files
author
DvirDukhan
committed
added low level api return redis types
1 parent 1a3f394 commit 24f02b7

File tree

8 files changed

+42
-2
lines changed

8 files changed

+42
-2
lines changed

src/model.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,3 +645,7 @@ int RedisAI_Parse_ModelRun_RedisCommand(RedisModuleCtx *ctx,
645645
}
646646
return argpos;
647647
}
648+
649+
RedisModuleType *RAI_getModelRedisType(void) {
650+
return RedisAI_ModelType;
651+
}

src/model.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,11 @@ int RedisAI_Parse_ModelRun_RedisCommand(
225225
RAI_ModelRunCtx** mctx, RedisModuleString*** outkeys, RAI_Model** mto,
226226
int useLocalContext, AI_dict** localContextDict, int use_chaining_operator,
227227
const char* chaining_operator, RAI_Error* error);
228+
229+
/**
230+
* @brief Returns the redis module type representing a model.
231+
* @return redis module type representing a model.
232+
*/
233+
RedisModuleType *RAI_ModelRedisType(void);
234+
228235
#endif /* SRC_MODEL_H_ */

src/redisai.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ static int RedisAI_RegisterApi(RedisModuleCtx* ctx) {
966966
REGISTER_API(TensorDim, ctx);
967967
REGISTER_API(TensorByteSize, ctx);
968968
REGISTER_API(TensorData, ctx);
969+
REGISTER_API(TensorRedisType, ctx);
969970

970971
REGISTER_API(ModelCreate, ctx);
971972
REGISTER_API(ModelFree, ctx);
@@ -978,6 +979,7 @@ static int RedisAI_RegisterApi(RedisModuleCtx* ctx) {
978979
REGISTER_API(ModelRun, ctx);
979980
REGISTER_API(ModelSerialize, ctx);
980981
REGISTER_API(ModelGetShallowCopy, ctx);
982+
REGISTER_API(ModelRedisType, ctx);
981983

982984
REGISTER_API(ScriptCreate, ctx);
983985
REGISTER_API(ScriptFree, ctx);
@@ -989,6 +991,7 @@ static int RedisAI_RegisterApi(RedisModuleCtx* ctx) {
989991
REGISTER_API(ScriptRunCtxFree, ctx);
990992
REGISTER_API(ScriptRun, ctx);
991993
REGISTER_API(ScriptGetShallowCopy, ctx);
994+
REGISTER_API(ScriptRedisType, ctx);
992995

993996
return REDISMODULE_OK;
994997
}

src/redisai.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ int MODULE_API_FUNC(RedisAI_TensorNumDims)(RAI_Tensor* t);
7878
long long MODULE_API_FUNC(RedisAI_TensorDim)(RAI_Tensor* t, int dim);
7979
size_t MODULE_API_FUNC(RedisAI_TensorByteSize)(RAI_Tensor* t);
8080
char* MODULE_API_FUNC(RedisAI_TensorData)(RAI_Tensor* t);
81+
RedisModuleType MODULE_API_FUNC(RedisAI_TensorRedisType)(void);
8182

8283
RAI_Model* MODULE_API_FUNC(RedisAI_ModelCreate)(int backend, char* devicestr, char* tag, RAI_ModelOpts opts,
8384
size_t ninputs, const char **inputs,
@@ -93,6 +94,7 @@ void MODULE_API_FUNC(RedisAI_ModelRunCtxFree)(RAI_ModelRunCtx* mctx);
9394
int MODULE_API_FUNC(RedisAI_ModelRun)(RAI_ModelRunCtx** mctx, long long n, RAI_Error* err);
9495
RAI_Model* MODULE_API_FUNC(RedisAI_ModelGetShallowCopy)(RAI_Model* model);
9596
int MODULE_API_FUNC(RedisAI_ModelSerialize)(RAI_Model *model, char **buffer, size_t *len, RAI_Error *err);
97+
RedisModuleType MODULE_API_FUNC(RedisAI_ModelRedisType)(void);
9698

9799
RAI_Script* MODULE_API_FUNC(RedisAI_ScriptCreate)(char* devicestr, char* tag, const char* scriptdef, RAI_Error* err);
98100
void MODULE_API_FUNC(RedisAI_ScriptFree)(RAI_Script* script, RAI_Error* err);
@@ -104,6 +106,7 @@ RAI_Tensor* MODULE_API_FUNC(RedisAI_ScriptRunCtxOutputTensor)(RAI_ScriptRunCtx*
104106
void MODULE_API_FUNC(RedisAI_ScriptRunCtxFree)(RAI_ScriptRunCtx* sctx);
105107
int MODULE_API_FUNC(RedisAI_ScriptRun)(RAI_ScriptRunCtx* sctx, RAI_Error* err);
106108
RAI_Script* MODULE_API_FUNC(RedisAI_ScriptGetShallowCopy)(RAI_Script* script);
109+
RedisModuleType MODULE_API_FUNC(RedisAI_ScriptRedisType)(void);
107110

108111
int MODULE_API_FUNC(RedisAI_GetLLAPIVersion)();
109112

@@ -145,6 +148,7 @@ static int RedisAI_Initialize(RedisModuleCtx* ctx){
145148
REDISAI_MODULE_INIT_FUNCTION(ctx, TensorDim);
146149
REDISAI_MODULE_INIT_FUNCTION(ctx, TensorByteSize);
147150
REDISAI_MODULE_INIT_FUNCTION(ctx, TensorData);
151+
REDISAI_MODULE_INIT_FUNCTION(ctx, TensorRedisType);
148152

149153
REDISAI_MODULE_INIT_FUNCTION(ctx, ModelCreate);
150154
REDISAI_MODULE_INIT_FUNCTION(ctx, ModelFree);
@@ -157,6 +161,7 @@ static int RedisAI_Initialize(RedisModuleCtx* ctx){
157161
REDISAI_MODULE_INIT_FUNCTION(ctx, ModelRun);
158162
REDISAI_MODULE_INIT_FUNCTION(ctx, ModelGetShallowCopy);
159163
REDISAI_MODULE_INIT_FUNCTION(ctx, ModelSerialize);
164+
REDISAI_MODULE_INIT_FUNCTION(ctx, ModelRedisType);
160165

161166
REDISAI_MODULE_INIT_FUNCTION(ctx, ScriptCreate);
162167
REDISAI_MODULE_INIT_FUNCTION(ctx, ScriptFree);
@@ -168,6 +173,7 @@ static int RedisAI_Initialize(RedisModuleCtx* ctx){
168173
REDISAI_MODULE_INIT_FUNCTION(ctx, ScriptRunCtxFree);
169174
REDISAI_MODULE_INIT_FUNCTION(ctx, ScriptRun);
170175
REDISAI_MODULE_INIT_FUNCTION(ctx, ScriptGetShallowCopy);
176+
REDISAI_MODULE_INIT_FUNCTION(ctx, ScriptRedisType);
171177

172178
if(RedisAI_GetLLAPIVersion() < REDISAI_LLAPI_VERSION){
173179
return REDISMODULE_ERR;

src/script.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,8 @@ void RedisAI_ReplyOrSetError(RedisModuleCtx *ctx, RAI_Error *error, RAI_ErrorCod
334334
} else {
335335
RedisModule_ReplyWithError(ctx, errorMessage);
336336
}
337-
}
337+
}
338+
339+
RedisModuleType *RAI_ScriptRedisType(void) {
340+
return RedisAI_ScriptType;
341+
}

src/script.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,10 @@ int RedisAI_Parse_ScriptRun_RedisCommand(RedisModuleCtx *ctx,
192192
*/
193193
void RedisAI_ReplyOrSetError(RedisModuleCtx *ctx, RAI_Error *error, RAI_ErrorCode code, const char* errorMessage );
194194

195+
/**
196+
* @brief Returns the redis module type representing a script.
197+
* @return redis module type representing a script.
198+
*/
199+
RedisModuleType *RAI_ScriptRedisType(void);
200+
195201
#endif /* SRC_SCRIPT_H_ */

src/tensor.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,4 +1071,8 @@ int RAI_parseTensorGetArgs(RedisModuleCtx *ctx, RedisModuleString **argv, int ar
10711071

10721072
// return command arity as the number of processed args
10731073
return argc;
1074-
}
1074+
}
1075+
1076+
RedisModuleType *RAI_TensorRedisType(void) {
1077+
return RedisAI_TensorType;
1078+
}

src/tensor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,10 @@ int RAI_parseTensorSetArgs(RedisModuleCtx* ctx, RedisModuleString** argv,
378378
int RAI_parseTensorGetArgs(RedisModuleCtx* ctx, RedisModuleString** argv,
379379
int argc, RAI_Tensor* t);
380380

381+
/**
382+
* @brief Returns the redis module type representing a tensor.
383+
* @return redis module type representing a tensor.
384+
*/
385+
RedisModuleType *RAI_TensorRedisType(void);
386+
381387
#endif /* SRC_TENSOR_H_ */

0 commit comments

Comments
 (0)