Skip to content

Commit 21abddd

Browse files
author
MeirShpilraien
committed
added redisdl.h that expose redisdl api to be used by other modules
1 parent 0d459c5 commit 21abddd

File tree

6 files changed

+233
-110
lines changed

6 files changed

+233
-110
lines changed

src/graph.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ static void Graph_RdbSave(RedisModuleIO *rdb, void *value){
3333
}
3434

3535
static void Graph_DTFree(void *value){
36-
Graph_Free(value);
36+
RDL_GraphFree(value);
3737
}
3838

39-
int Graph_Init(RedisModuleCtx* ctx){
39+
int RDL_GraphInit(RedisModuleCtx* ctx){
4040
RedisModuleTypeMethods tmGraph = {
4141
.version = REDISMODULE_TYPE_METHOD_VERSION,
4242
.rdb_load = Graph_RdbLoad,
@@ -51,7 +51,7 @@ int Graph_Init(RedisModuleCtx* ctx){
5151
return RedisDL_GraphType != NULL;
5252
}
5353

54-
RDL_Graph* Graph_Create(const char* prefix, const char* graphdef, size_t graphlen){
54+
RDL_Graph* RDL_GraphCreate(const char* prefix, const char* graphdef, size_t graphlen){
5555
TF_Graph* graph = TF_NewGraph();
5656

5757
TF_ImportGraphDefOptions* options = TF_NewImportGraphDefOptions();
@@ -95,7 +95,7 @@ RDL_Graph* Graph_Create(const char* prefix, const char* graphdef, size_t graphle
9595
return ret;
9696
}
9797

98-
void Graph_Free(RDL_Graph* graph){
98+
void RDL_GraphFree(RDL_Graph* graph){
9999
if(--graph->refCount > 0){
100100
return;
101101
}
@@ -125,10 +125,10 @@ void Graph_Free(RDL_Graph* graph){
125125
RedisModule_Free(graph);
126126
}
127127

128-
RDL_GraphRunCtx* Graph_RunCtxCreate(RDL_Graph* graph){
128+
RDL_GraphRunCtx* RDL_RunCtxCreate(RDL_Graph* graph){
129129
#define PARAM_INITIAL_SIZE 10
130130
RDL_GraphRunCtx* gctx = RedisModule_Alloc(sizeof(*gctx));
131-
gctx->graph = Graph_GetShallowCopy(graph);
131+
gctx->graph = RDL_GraphGetShallowCopy(graph);
132132
gctx->inputs = array_new(RDL_GraphCtxParam, PARAM_INITIAL_SIZE);
133133
gctx->outputs = array_new(RDL_GraphCtxParam, PARAM_INITIAL_SIZE);
134134
return gctx;
@@ -143,46 +143,46 @@ static int Graph_RunCtxAddParam(RDL_GraphRunCtx* gctx, RDL_GraphCtxParam* paramA
143143
}
144144
RDL_GraphCtxParam param = {
145145
.name = port,
146-
.tensor = tensor ? Tensor_GetShallowCopy(tensor): NULL,
146+
.tensor = tensor ? RDL_TensorGetShallowCopy(tensor): NULL,
147147
};
148148
paramArr = array_append(paramArr, param);
149149
return 1;
150150
}
151151

152-
int Graph_RunCtxAddInput(RDL_GraphRunCtx* gctx, const char* inputName, RDL_Tensor* inputTensor){
152+
int RDL_RunCtxAddInput(RDL_GraphRunCtx* gctx, const char* inputName, RDL_Tensor* inputTensor){
153153
return Graph_RunCtxAddParam(gctx, gctx->inputs, inputName, inputTensor);
154154
}
155155

156-
int Graph_RunCtxAddOutput(RDL_GraphRunCtx* gctx, const char* outputName){
156+
int RDL_RunCtxAddOutput(RDL_GraphRunCtx* gctx, const char* outputName){
157157
return Graph_RunCtxAddParam(gctx, gctx->outputs, outputName, NULL);
158158
}
159159

160-
size_t Graph_RunCtxNumOutputs(RDL_GraphRunCtx* gctx){
160+
size_t RDL_RunCtxNumOutputs(RDL_GraphRunCtx* gctx){
161161
return array_len(gctx->outputs);
162162
}
163163

164-
RDL_Tensor* Graph_RunCtxOutputTensor(RDL_GraphRunCtx* gctx, size_t index){
165-
assert(Graph_RunCtxNumOutputs(gctx) > index && index >= 0);
164+
RDL_Tensor* RDL_RunCtxOutputTensor(RDL_GraphRunCtx* gctx, size_t index){
165+
assert(RDL_RunCtxNumOutputs(gctx) > index && index >= 0);
166166
return gctx->outputs[index].tensor;
167167
}
168168

169-
void Graph_RunCtxFreeInternals(RDL_GraphRunCtx* gctx){
169+
void RDL_RunCtxFree(RDL_GraphRunCtx* gctx){
170170
for(size_t i = 0 ; i < array_len(gctx->inputs) ; ++i){
171-
Tensor_Free(gctx->inputs[i].tensor);
171+
RDL_TensorFree(gctx->inputs[i].tensor);
172172
}
173173
array_free(gctx->inputs);
174174

175175
for(size_t i = 0 ; i < array_len(gctx->outputs) ; ++i){
176176
if(gctx->outputs[i].tensor){
177-
Tensor_Free(gctx->outputs[i].tensor);
177+
RDL_TensorFree(gctx->outputs[i].tensor);
178178
}
179179
}
180180
array_free(gctx->outputs);
181181

182-
Graph_Free(gctx->graph);
182+
RDL_GraphFree(gctx->graph);
183183
}
184184

185-
int Graph_Run(RDL_GraphRunCtx* gctx){
185+
int RDL_GraphRun(RDL_GraphRunCtx* gctx){
186186
TF_Status *status = TF_NewStatus();
187187

188188
TF_Tensor* inputTensorsValues[array_len(gctx->inputs)];
@@ -191,7 +191,7 @@ int Graph_Run(RDL_GraphRunCtx* gctx){
191191
TF_Output outputs[array_len(gctx->outputs)];
192192

193193
for(size_t i = 0 ; i < array_len(gctx->inputs) ; ++i){
194-
inputTensorsValues[i] = Tensor_GetTensor(gctx->inputs[i].tensor);
194+
inputTensorsValues[i] = RDL_TensorGetTensor(gctx->inputs[i].tensor);
195195
inputs[i] = gctx->inputs[i].name;
196196
}
197197

@@ -212,14 +212,14 @@ int Graph_Run(RDL_GraphRunCtx* gctx){
212212
}
213213

214214
for(size_t i = 0 ; i < array_len(gctx->outputs) ; ++i){
215-
gctx->outputs[i].tensor = Tensor_CreateFromTensor(outputTensorsValues[i]);
215+
gctx->outputs[i].tensor = RDL_TensorCreateFromTensor(outputTensorsValues[i]);
216216
}
217217

218218
TF_DeleteStatus(status);
219219
return 1;
220220
}
221221

222-
RDL_Graph* Graph_GetShallowCopy(RDL_Graph* graph){
222+
RDL_Graph* RDL_GraphGetShallowCopy(RDL_Graph* graph){
223223
++graph->refCount;
224224
return graph;
225225
}

src/graph.h

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,19 @@
1212
#include "redismodule.h"
1313
#include "tensor.h"
1414

15-
typedef struct RDL_Graph RDL_Graph;
16-
17-
typedef struct RDL_GraphCtxParam RDL_GraphCtxParam;
18-
19-
typedef struct RDL_GraphRunCtx RDL_GraphRunCtx;
20-
2115
extern RedisModuleType *RedisDL_GraphType;
2216

23-
int Graph_Init(RedisModuleCtx* ctx);
24-
RDL_Graph* Graph_Create(const char* prefix, const char* graphdef, size_t graphlen);
25-
void Graph_Free(RDL_Graph* graph);
26-
RDL_GraphRunCtx* Graph_RunCtxCreate(RDL_Graph* graph);
27-
int Graph_RunCtxAddInput(RDL_GraphRunCtx* gctx, const char* inputName, RDL_Tensor* inputTensor);
28-
int Graph_RunCtxAddOutput(RDL_GraphRunCtx* gctx, const char* outputName);
29-
size_t Graph_RunCtxNumOutputs(RDL_GraphRunCtx* gctx);
30-
RDL_Tensor* Graph_RunCtxOutputTensor(RDL_GraphRunCtx* gctx, size_t index);
31-
void Graph_RunCtxFreeInternals(RDL_GraphRunCtx* gctx);
32-
int Graph_Run(RDL_GraphRunCtx* gctx);
33-
RDL_Graph* Graph_GetShallowCopy(RDL_Graph* graph);
17+
int RDL_GraphInit(RedisModuleCtx* ctx);
18+
RDL_Graph* RDL_GraphCreate(const char* prefix, const char* graphdef, size_t graphlen);
19+
void RDL_GraphFree(RDL_Graph* graph);
20+
RDL_GraphRunCtx* RDL_RunCtxCreate(RDL_Graph* graph);
21+
int RDL_RunCtxAddInput(RDL_GraphRunCtx* gctx, const char* inputName, RDL_Tensor* inputTensor);
22+
int RDL_RunCtxAddOutput(RDL_GraphRunCtx* gctx, const char* outputName);
23+
size_t RDL_RunCtxNumOutputs(RDL_GraphRunCtx* gctx);
24+
RDL_Tensor* RDL_RunCtxOutputTensor(RDL_GraphRunCtx* gctx, size_t index);
25+
void RDL_RunCtxFree(RDL_GraphRunCtx* gctx);
26+
int RDL_GraphRun(RDL_GraphRunCtx* gctx);
27+
RDL_Graph* RDL_GraphGetShallowCopy(RDL_Graph* graph);
3428

3529

3630

0 commit comments

Comments
 (0)