Skip to content

Commit 353c7c2

Browse files
authored
Merge pull request #629 from RedisAI/folder_structure_refactor
Folder structure refactor
2 parents d6d98ef + 7c2c2f0 commit 353c7c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+258
-753
lines changed

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
4444

4545
# Add -fno-omit-frame-pointer to avoid seeing incomplete stack traces
4646
set(CMAKE_COMMON_FLAGS_DEBUG "-g -ggdb -fno-omit-frame-pointer -D_DEBUG -DVALGRIND -include \
47-
${CMAKE_CURRENT_SOURCE_DIR}/src/common.h -I${CMAKE_CURRENT_SOURCE_DIR}/opt")
47+
${CMAKE_CURRENT_SOURCE_DIR}/src/config/gdb_config.h -I${CMAKE_CURRENT_SOURCE_DIR}/opt")
4848
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_COMMON_FLAGS_DEBUG}")
4949
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_COMMON_FLAGS_DEBUG}")
5050

@@ -98,6 +98,7 @@ GET_FILENAME_COMPONENT(installAbs
9898
#----------------------------------------------------------------------------------------------
9999

100100
INCLUDE_DIRECTORIES(${depsAbs}/dlpack/include)
101+
INCLUDE_DIRECTORIES(src)
101102
IF(BUILD_TF)
102103
INCLUDE_DIRECTORIES(${depsAbs}/libtensorflow/include)
103104
ENDIF()
@@ -182,7 +183,7 @@ IF(BUILD_TFLITE)
182183
# Find TensorFlow Lite stuff and build our wrapper
183184
INCLUDE_DIRECTORIES(util/libtflite_c)
184185

185-
ADD_SUBDIRECTORY(src/libtflite_c)
186+
ADD_SUBDIRECTORY(src/backends/libtflite_c)
186187
ENDIF()
187188

188189
#----------------------------------------------------------------------------------------------
@@ -194,7 +195,7 @@ IF(BUILD_TORCH)
194195

195196
INCLUDE_DIRECTORIES(util/libtorch_c)
196197

197-
ADD_SUBDIRECTORY(src/libtorch_c)
198+
ADD_SUBDIRECTORY(src/backends/libtorch_c)
198199
ENDIF()
199200

200201
#----------------------------------------------------------------------------------------------

src/CMakeLists.txt

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ if (CMAKE_BUILD_TYPE STREQUAL Debug)
33
endif()
44

55
file (GLOB_RECURSE SERIALIZATION_SRC
6-
tensor.c
7-
model.c
8-
script.c
9-
backends.c
6+
redis_ai_objects/tensor.c
7+
redis_ai_objects/model.c
8+
redis_ai_objects/script.c
9+
backends/backends.c
1010
stats.c
1111
config.c
1212
serialization/*.c)
1313

1414
file (GLOB BACKEND_COMMON_SRC
1515
backends/util.c
16-
err.c
16+
redis_ai_objects/err.c
1717
util/dict.c
18-
tensor.c
18+
redis_ai_objects/tensor.c
1919
util/string_utils.c
2020
serialization/ai_datatypes.c)
2121

@@ -24,28 +24,26 @@ ADD_LIBRARY(redisai_obj OBJECT
2424
util/queue.c
2525
util/string_utils.c
2626
redisai.c
27-
command_parser.c
28-
run_info.c
29-
background_workers.c
30-
config.c
31-
DAG/dag.c
32-
DAG/dag_parser.c
33-
DAG/dag_builder.c
34-
DAG/dag_execute.c
35-
modelRun_ctx.c
36-
backends.c
27+
execution/command_parser.c
28+
execution/run_info.c
29+
execution/background_workers.c
30+
config/config.c
31+
execution/DAG/dag.c
32+
execution/DAG/dag_parser.c
33+
execution/DAG/dag_builder.c
34+
execution/DAG/dag_execute.c
35+
execution/modelRun_ctx.c
36+
backends/backends.c
3737
backends/util.c
38-
model.c
39-
err.c
40-
script.c
41-
stats.c
42-
tensor.c
38+
redis_ai_objects/model.c
39+
redis_ai_objects/err.c
40+
redis_ai_objects/script.c
41+
redis_ai_objects/stats.c
42+
redis_ai_objects/tensor.c
4343
rmutil/alloc.c
4444
rmutil/sds.c
4545
rmutil/args.c
46-
rmutil/heap.c
47-
rmutil/priority_queue.c
48-
rmutil/vector.c run_info.c
46+
execution/run_info.c
4947
redis_ai_types/model_type.c
5048
redis_ai_types/tensor_type.c
5149
redis_ai_types/script_type.c
File renamed without changes.

src/backends.h renamed to src/backends/backends.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
*
77
*/
88

9-
#ifndef SRC_BACKENDS_H_
10-
#define SRC_BACKENDS_H_
9+
#pragma once
1110

12-
#include "config.h"
13-
#include "err.h"
14-
#include "model_struct.h"
15-
#include "script_struct.h"
16-
#include "tensor.h"
11+
#include "config/config.h"
12+
#include "redis_ai_objects/err.h"
13+
#include "redis_ai_objects/tensor.h"
14+
#include "redis_ai_objects/model_struct.h"
15+
#include "redis_ai_objects/script_struct.h"
1716

1817
/*
1918
* To register a new backend to be loaded by the module, the backend needs to
@@ -98,5 +97,3 @@ int RAI_LoadBackend(RedisModuleCtx *ctx, int backend, const char *path);
9897
int RAI_LoadDefaultBackend(RedisModuleCtx *ctx, int backend);
9998

10099
const char *RAI_BackendName(int backend);
101-
102-
#endif

src/libtflite_c/tflite_c.cpp renamed to src/backends/libtflite_c/tflite_c.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#include "tflite_c.h"
2-
#include <iostream>
31
#include <sstream>
2+
#include <iostream>
3+
#include "tflite_c.h"
4+
#include "redismodule.h"
5+
#include "tensorflow/lite/model.h"
46
#include "tensorflow/lite/interpreter.h"
57
#include "tensorflow/lite/kernels/register.h"
6-
#include "tensorflow/lite/model.h"
78
#include "tensorflow/lite/tools/evaluation/utils.h"
8-
#include "../redismodule.h"
99

1010
namespace {
1111

src/libtflite_c/tflite_c.h renamed to src/backends/libtflite_c/tflite_c.h

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

43
#include "dlpack/dlpack.h"
54

@@ -30,5 +29,3 @@ const char *tfliteModelOutputNameAtIndex(void *modelCtx, size_t index, char **er
3029
#ifdef __cplusplus
3130
}
3231
#endif
33-
34-
#endif // __TFLITE_C_H__

src/libtorch_c/torch_c.cpp renamed to src/backends/libtorch_c/torch_c.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "torch_c.h"
22
#include "torch/torch.h"
3+
#include "redismodule.h"
4+
#include "ATen/Functions.h"
35
#include "torch/csrc/jit/serialization/import.h"
46
#include "torch/csrc/jit/api/compilation_unit.h"
5-
#include "ATen/Functions.h"
6-
#include "../redismodule.h"
77

88
#include <iostream>
99
#include <sstream>

src/libtorch_c/torch_c.h renamed to src/backends/libtorch_c/torch_c.h

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

43
#include "dlpack/dlpack.h"
54

@@ -43,5 +42,3 @@ size_t torchModelNumOutputs(void *modelCtx, char **error);
4342
#ifdef __cplusplus
4443
}
4544
#endif
46-
47-
#endif // __TORCH_C_H__

src/libtorch_c/torch_extensions/torch_redis.cpp renamed to src/backends/libtorch_c/torch_extensions/torch_redis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <string>
22
#include "torch_redis.h"
3-
#include "../../redismodule.h"
3+
#include "../../../redismodule.h"
44

55
torch::IValue IValueFromRedisReply(RedisModuleCallReply *reply){
66

src/backends/onnxruntime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#define REDISMODULE_MAIN
22
#include <cuda_provider_factory.h>
3-
#include "backends/onnxruntime.h"
43
#include "backends/util.h"
5-
#include "tensor.h"
6-
#include "util/arr_rm_alloc.h"
74
#include <stdatomic.h>
5+
#include "util/arr.h"
6+
#include "backends/onnxruntime.h"
7+
#include "redis_ai_objects/tensor.h"
88

99
#include "onnxruntime_c_api.h"
1010

src/backends/onnxruntime.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
#ifndef SRC_BACKENDS_ONNXRUNTIME_H_
2-
#define SRC_BACKENDS_ONNXRUNTIME_H_
1+
#pragma once
32

4-
#include "config.h"
5-
#include "tensor_struct.h"
6-
#include "model_struct.h"
7-
#include "err.h"
3+
#include "config/config.h"
4+
#include "redis_ai_objects/err.h"
5+
#include "redis_ai_objects/tensor_struct.h"
6+
#include "redis_ai_objects/model_struct.h"
87

98
unsigned long long RAI_GetMemoryInfoORT(void);
109

@@ -22,5 +21,3 @@ int RAI_ModelRunORT(RAI_ModelRunCtx **mctxs, RAI_Error *error);
2221
int RAI_ModelSerializeORT(RAI_Model *model, char **buffer, size_t *len, RAI_Error *error);
2322

2423
const char *RAI_GetBackendVersionORT(void);
25-
26-
#endif /* SRC_BACKENDS_ONNXRUNTIME_H_ */

src/backends/tensorflow.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#define REDISMODULE_MAIN
2-
#include "backends/tensorflow.h"
32
#include "backends/util.h"
4-
#include "tensor.h"
5-
#include "util/arr_rm_alloc.h"
6-
#include "model.h"
3+
#include "backends/tensorflow.h"
4+
#include "util/arr.h"
5+
#include "redis_ai_objects/model.h"
6+
#include "redis_ai_objects/tensor.h"
77

88
#include "tensorflow/c/c_api.h"
99

src/backends/tensorflow.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
#ifndef SRC_BACKENDS_TENSORFLOW_H_
2-
#define SRC_BACKENDS_TENSORFLOW_H_
1+
#pragma once
32

4-
#include "config.h"
5-
#include "tensor_struct.h"
6-
#include "model_struct.h"
7-
#include "err.h"
3+
#include "config/config.h"
4+
#include "redis_ai_objects/err.h"
5+
#include "redis_ai_objects/tensor_struct.h"
6+
#include "redis_ai_objects/model_struct.h"
87

98
int RAI_InitBackendTF(int (*get_api_fn)(const char *, void *));
109

@@ -20,5 +19,3 @@ int RAI_ModelRunTF(RAI_ModelRunCtx **mctxs, RAI_Error *error);
2019
int RAI_ModelSerializeTF(RAI_Model *model, char **buffer, size_t *len, RAI_Error *error);
2120

2221
const char *RAI_GetBackendVersionTF(void);
23-
24-
#endif /* SRC_BACKENDS_TENSORFLOW_H_ */

src/backends/tflite.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#define REDISMODULE_MAIN
2-
#include "backends/tflite.h"
32
#include "backends/util.h"
4-
#include "tensor.h"
5-
#include "util/arr_rm_alloc.h"
3+
#include "backends/tflite.h"
4+
#include "util/arr.h"
65
#include "libtflite_c/tflite_c.h"
6+
#include "redis_ai_objects/tensor.h"
77

88
int RAI_InitBackendTFLite(int (*get_api_fn)(const char *, void *)) {
99
get_api_fn("RedisModule_Alloc", ((void **)&RedisModule_Alloc));

src/backends/tflite.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22

3-
#include "config.h"
4-
#include "tensor_struct.h"
5-
#include "model_struct.h"
6-
#include "err.h"
3+
#include "config/config.h"
4+
#include "redis_ai_objects/err.h"
5+
#include "redis_ai_objects/model_struct.h"
6+
#include "redis_ai_objects/tensor_struct.h"
77

88
int RAI_InitBackendTFLite(int (*get_api_fn)(const char *, void *));
99

src/backends/torch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#define REDISMODULE_MAIN
2-
#include "backends/torch.h"
32
#include "backends/util.h"
4-
#include "tensor.h"
5-
#include "util/arr_rm_alloc.h"
3+
#include "backends/torch.h"
4+
#include "util/arr.h"
65
#include "libtorch_c/torch_c.h"
6+
#include "redis_ai_objects/tensor.h"
77

88
int RAI_InitBackendTorch(int (*get_api_fn)(const char *, void *)) {
99
get_api_fn("RedisModule_Alloc", ((void **)&RedisModule_Alloc));

src/backends/torch.h

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

3-
#include "config.h"
4-
#include "tensor_struct.h"
5-
#include "script_struct.h"
6-
#include "model_struct.h"
7-
#include "err.h"
3+
#include "config/config.h"
4+
#include "redis_ai_objects/err.h"
5+
#include "redis_ai_objects/model_struct.h"
6+
#include "redis_ai_objects/tensor_struct.h"
7+
#include "redis_ai_objects/script_struct.h"
88

99
int RAI_InitBackendTorch(int (*get_api_fn)(const char *, void *));
1010

src/backends/util.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
#ifndef SRC_BACKENDS_UTIL_H_
2-
#define SRC_BACKENDS_UTIL_H_
1+
#pragma once
32

43
#include <stdint.h>
54
#include <stdio.h>
65
#include <strings.h>
76

8-
#include "config.h"
7+
#include "config/config.h"
98

109
int parseDeviceStr(const char *devicestr, RAI_Device *device, int64_t *deviceid);
11-
12-
#endif /* SRC_BACKENDS_UTIL_H_ */

src/config.c renamed to src/config/config.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
#include <sys/time.h>
66
#include <unistd.h>
77

8-
#include "backends.h"
9-
#include "backends/util.h"
10-
#include "background_workers.h"
11-
#include "err.h"
128
#include "redismodule.h"
139
#include "rmutil/alloc.h"
14-
#include "util/arr_rm_alloc.h"
10+
#include "backends/util.h"
11+
#include "backends/backends.h"
1512
#include "util/dict.h"
1613
#include "util/queue.h"
14+
#include "util/arr.h"
15+
#include "execution/background_workers.h"
1716

1817
long long backends_intra_op_parallelism; // number of threads used within an
1918
// individual op for parallelism.

src/config.h renamed to src/config/config.h

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

43
#include "redismodule.h"
54

@@ -159,5 +158,3 @@ int RAI_configParamParse(RedisModuleCtx *ctx, const char *key, const char *val,
159158
* @return REDISMODULE_OK on success, or REDISMODULE_ERR if the DAGRUN failed
160159
*/
161160
int RAI_loadTimeConfig(RedisModuleCtx *ctx, RedisModuleString *const *argv, int argc);
162-
163-
#endif /* SRC_CONFIG_H_ */
File renamed without changes.

0 commit comments

Comments
 (0)