Skip to content

Commit 0e68fc1

Browse files
author
DvirDukhan
committed
tf version
1 parent 8a3a3b2 commit 0e68fc1

File tree

6 files changed

+82
-4
lines changed

6 files changed

+82
-4
lines changed

src/backends.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ int RAI_LoadBackend_TensorFlow(RedisModuleCtx *ctx, const char *path) {
132132
return REDISMODULE_ERR;
133133
}
134134

135+
backend.get_version = (const char*(*)(void))(unsigned long)dlsym(handle, "RAI_GetBackendVersionTF");
136+
if (backend.get_version == NULL) {
137+
dlclose(handle);
138+
RedisModule_Log(ctx, "warning",
139+
"Backend does not export RAI_GetBackendVersionTF. TF backend "
140+
"not loaded from %s",
141+
path);
142+
return REDISMODULE_ERR;
143+
}
144+
135145
RAI_backends.tf = backend;
136146

137147
RedisModule_Log(ctx, "notice", "TF backend loaded from %s", path);

src/backends.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ typedef struct RAI_LoadedBackend {
7474
// RAI_ScriptRunCtx pointer
7575
int (*script_run)(RAI_ScriptRunCtx *, RAI_Error *);
7676

77+
// Returns the backend version.
78+
const char* (*get_version)(void);
79+
7780
} RAI_LoadedBackend;
7881

7982
typedef struct RAI_LoadedBackends {

src/backends/tensorflow.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,3 +591,7 @@ int RAI_ModelSerializeTF(RAI_Model *model, char **buffer, size_t *len, RAI_Error
591591

592592
return 0;
593593
}
594+
595+
const char* RAI_GetBackendVersionTF(void) {
596+
return TF_Version();
597+
}

src/backends/tensorflow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ int RAI_ModelRunTF(RAI_ModelRunCtx **mctxs, RAI_Error *error);
1919

2020
int RAI_ModelSerializeTF(RAI_Model *model, char **buffer, size_t *len, RAI_Error *error);
2121

22+
const char* RAI_GetBackendVersionTF(void);
23+
2224
#endif /* SRC_BACKENDS_TENSORFLOW_H_ */

src/redisai.c

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,12 +805,73 @@ int RedisAI_ScriptScan_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **arg
805805
return REDISMODULE_OK;
806806
}
807807

808+
void _RedisAI_Info(RedisModuleCtx* ctx) {
809+
RedisModuleString* rai_version = RedisModule_CreateStringPrintf(ctx, "%d.%d.%d", REDISAI_VERSION_MAJOR, REDISAI_VERSION_MINOR, REDISAI_VERSION_PATCH);
810+
RedisModuleString* llapi_version = RedisModule_CreateStringPrintf(ctx, "%d", REDISAI_LLAPI_VERSION);
811+
RedisModuleString* rdb_version = RedisModule_CreateStringPrintf(ctx, "%llu", REDISAI_ENC_VER);
812+
813+
int reponse_len = 6;
814+
815+
if(RAI_backends.tf.get_version){
816+
reponse_len+=2;
817+
}
818+
819+
if(RAI_backends.torch.get_version){
820+
reponse_len+=2;
821+
}
822+
823+
if(RAI_backends.tflite.get_version){
824+
reponse_len+=2;
825+
}
826+
827+
if(RAI_backends.onnx.get_version){
828+
reponse_len+=2;
829+
}
830+
831+
RedisModule_ReplyWithArray(ctx, reponse_len);
832+
833+
RedisModule_ReplyWithSimpleString(ctx, "Version");
834+
RedisModule_ReplyWithString(ctx, rai_version);
835+
836+
// TODO: Add Git SHA
837+
838+
RedisModule_ReplyWithSimpleString(ctx, "Low Level API Version");
839+
RedisModule_ReplyWithString(ctx, llapi_version);
840+
841+
842+
RedisModule_ReplyWithSimpleString(ctx, "RDB Encoding version");
843+
RedisModule_ReplyWithString(ctx, llapi_version);
844+
845+
if(RAI_backends.tf.get_version){
846+
RedisModule_ReplyWithSimpleString(ctx, "TensorFlow version");
847+
RedisModule_ReplyWithSimpleString(ctx, RAI_backends.tf.get_version());
848+
}
849+
850+
if(RAI_backends.torch.get_version){
851+
RedisModule_ReplyWithSimpleString(ctx, "Torch version");
852+
RedisModule_ReplyWithSimpleString(ctx, RAI_backends.torch.get_version());
853+
}
854+
855+
856+
RedisModule_FreeString(ctx, rai_version);
857+
RedisModule_FreeString(ctx, llapi_version);
858+
RedisModule_FreeString(ctx, rdb_version);
859+
}
860+
808861
/**
809862
* AI.INFO <model_or_script_key> [RESETSTAT]
810863
*/
811864
int RedisAI_Info_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
812-
if (argc != 2 && argc != 3)
865+
if (argc > 3)
813866
return RedisModule_WrongArity(ctx);
867+
868+
869+
if(argc == 1) {
870+
_RedisAI_Info(ctx);
871+
return REDISMODULE_OK;
872+
}
873+
874+
814875
RedisModuleString *runkey = argv[1];
815876
struct RedisAI_RunStats *rstats = NULL;
816877
if (RAI_GetRunStats(runkey, &rstats) == REDISMODULE_ERR) {

src/version.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef SRC_VERSION_H_
2-
#define SRC_VERSION_H_
1+
#pragma once
32

43
#define REDISAI_VERSION_MAJOR 99
54
#define REDISAI_VERSION_MINOR 99
@@ -13,4 +12,3 @@
1312

1413
static const long long REDISAI_ENC_VER = 1;
1514

16-
#endif /* SRC_VERSION_H_ */

0 commit comments

Comments
 (0)