Skip to content

Commit e3f75e4

Browse files
authored
Merge pull request #531 from RedisAI/Create_test_module_for_LLAPI
Create new test module that uses the LLAPI
2 parents 50b4b45 + 145c4e9 commit e3f75e4

File tree

12 files changed

+113
-19
lines changed

12 files changed

+113
-19
lines changed

src/background_workers.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void *RedisAI_Run_ThreadMain(void *arg) {
178178
RedisAI_RunInfo *orig = rinfo->orig_copy;
179179
long long dagRefCount = RAI_DagRunInfoFreeShallowCopy(rinfo);
180180
if (dagRefCount == 0) {
181-
RedisAI_OnFinishCtx finish_ctx = (RedisAI_RunInfo *)orig;
181+
RedisAI_OnFinishCtx *finish_ctx = orig;
182182
orig->OnFinish(finish_ctx, orig->private_data);
183183
}
184184

@@ -417,7 +417,7 @@ void *RedisAI_Run_ThreadMain(void *arg) {
417417
RedisAI_RunInfo *orig = rinfo->orig_copy;
418418
long long dagRefCount = RAI_DagRunInfoFreeShallowCopy(rinfo);
419419
if (dagRefCount == 0) {
420-
RedisAI_OnFinishCtx finish_ctx = (RedisAI_RunInfo *)orig;
420+
RedisAI_OnFinishCtx *finish_ctx = orig;
421421
orig->OnFinish(finish_ctx, orig->private_data);
422422
}
423423
} else {
@@ -449,7 +449,7 @@ void *RedisAI_Run_ThreadMain(void *arg) {
449449
// If the reference count for the DAG is zero and the client is still around,
450450
// then we actually unblock the client
451451
if (dagRefCount == 0) {
452-
RedisAI_OnFinishCtx finish_ctx = (RedisAI_RunInfo *)orig;
452+
RedisAI_OnFinishCtx *finish_ctx = orig;
453453
orig->OnFinish(finish_ctx, orig->private_data);
454454
}
455455
}

src/dag.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include "model.h"
3636
#include "redisai.h"
37+
#include "background_workers.h"
3738
#include "rmutil/alloc.h"
3839
#include "rmutil/args.h"
3940
#include "run_info.h"
@@ -889,7 +890,7 @@ void RedisAI_Disconnected(RedisModuleCtx *ctx, RedisModuleBlockedClient *bc) {
889890
RedisModule_Log(ctx, "warning", "Blocked client %p disconnected!", (void *)bc);
890891
}
891892

892-
// Parse the DAG run command and return true if it is a valid command to execute.
893+
// Parse the DAG run command and return REDISMODULE_OK only if it is a valid command to execute.
893894
static int DAG_CommandParser(RedisModuleCtx *ctx, RedisModuleString **argv, int argc, int dagMode,
894895
RedisAI_RunInfo **rinfo_ptr) {
895896

@@ -1229,7 +1230,7 @@ static int DAG_CommandParser(RedisModuleCtx *ctx, RedisModuleString **argv, int
12291230

12301231
// Add Shallow copies of the DAG run info to the devices' queues.
12311232
// Return REDISMODULE_OK in case of success, REDISMODULE_ERR if (at least) one insert op had failed.
1232-
static bool DAG_InsertDAGToQueue(RedisAI_RunInfo *rinfo) {
1233+
static int DAG_InsertDAGToQueue(RedisAI_RunInfo *rinfo) {
12331234
const char **devices = array_new(const char *, 10);
12341235

12351236
for (long long i = 0; i < array_len(rinfo->dagOps); i++) {
@@ -1280,7 +1281,7 @@ static bool DAG_InsertDAGToQueue(RedisAI_RunInfo *rinfo) {
12801281
array_free(rinfo_copies);
12811282
array_free(run_queues_info);
12821283
RAI_SetError(rinfo->err, RAI_EDAGRUN, "ERR Queue not initialized for device");
1283-
rinfo->OnFinish((RedisAI_OnFinishCtx)rinfo, rinfo->private_data);
1284+
rinfo->OnFinish((RedisAI_OnFinishCtx *)rinfo, rinfo->private_data);
12841285
return REDISMODULE_ERR;
12851286
}
12861287
run_queues_info = array_append(run_queues_info, run_queue_info);
@@ -1302,7 +1303,7 @@ static bool DAG_InsertDAGToQueue(RedisAI_RunInfo *rinfo) {
13021303
return REDISMODULE_OK;
13031304
}
13041305

1305-
void DAG_ReplyAndUnblock(RedisAI_OnFinishCtx ctx, void *private_data) {
1306+
void DAG_ReplyAndUnblock(RedisAI_OnFinishCtx *ctx, void *private_data) {
13061307

13071308
RedisAI_RunInfo *rinfo = (RedisAI_RunInfo *)ctx;
13081309
if (rinfo->client)

src/dag.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,6 @@ int RedisAI_ProcessDagRunCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
175175
* @param ctx Context object that contains errors and results
176176
* @param private_data is a pointer to the DAG run info struct
177177
*/
178-
void DAG_ReplyAndUnblock(RedisAI_OnFinishCtx ctx, void *private_data);
178+
void DAG_ReplyAndUnblock(RedisAI_OnFinishCtx *ctx, void *private_data);
179179

180180
#endif /* SRC_DAG_H_ */

src/model.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include "model.h"
11+
#include "version.h"
1112
#include "backends.h"
1213
#include "backends/util.h"
1314
#include "model_struct.h"

src/redisai.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
#ifndef SRC_REDISAI_H_
22
#define SRC_REDISAI_H_
33

4-
#include "background_workers.h"
5-
#include "model_struct.h"
6-
#include "redismodule.h"
7-
#include "util/dict.h"
8-
#include "version.h"
94
#include <stdbool.h>
5+
#include "redismodule.h"
106

11-
#define MODULE_API_FUNC(x) (*x)
7+
#define REDISAI_LLAPI_VERSION 1
8+
#define MODULE_API_FUNC(x) (*x)
129

1310
#ifndef REDISAI_H_INCLUDE
1411
typedef struct RAI_Tensor RAI_Tensor;
@@ -18,6 +15,8 @@ typedef struct RAI_Script RAI_Script;
1815
typedef struct RAI_ModelRunCtx RAI_ModelRunCtx;
1916
typedef struct RAI_ScriptRunCtx RAI_ScriptRunCtx;
2017
typedef struct RAI_Error RAI_Error;
18+
typedef struct RAI_ModelOpts RAI_ModelOpts;
19+
typedef struct RAI_OnFinishCtx RAI_OnFinishCtx;
2120
#endif
2221

2322
#define REDISAI_BACKEND_TENSORFLOW 0

src/redismodule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "C" {
2020
/* API versions. */
2121
#define REDISMODULE_APIVER_1 1
2222

23-
/* Version of the RedisModuleTypeMethods structure. Once the RedisModuleTypeMethods
23+
/* Version of the RedisModuleTypeMethods structure. Once the RedisModuleTypeMethods
2424
* structure is changed, this version number needs to be changed synchronistically. */
2525
#define REDISMODULE_TYPE_METHOD_VERSION 3
2626

src/run_info.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,20 @@ int RAI_InitDagOp(RAI_DagOp **result);
6363
*/
6464
void RAI_FreeDagOp(RAI_DagOp *dagOp);
6565

66+
typedef struct RedisAI_RunInfo RedisAI_RunInfo;
67+
6668
/**
6769
* This structure contains the context data at the end of the execution.
6870
* user can access results and errors through LLAPI.
6971
*/
70-
typedef void *RedisAI_OnFinishCtx;
72+
typedef RedisAI_RunInfo RedisAI_OnFinishCtx;
7173

7274
/**
7375
* @brief User defined callback to execute at the end of the run.
7476
* @param ctx parameter includes the running results and errors.
7577
* @param private_data is an optional pointer to the user's private data.
7678
*/
77-
typedef void (*RAI_OnFinishCB)(RedisAI_OnFinishCtx ctx, void *private_data);
79+
typedef void (*RAI_OnFinishCB)(RedisAI_OnFinishCtx *ctx, void *private_data);
7880

7981
/**
8082
* This structure represents the context in which RedisAI blocking commands
@@ -84,8 +86,6 @@ typedef void (*RAI_OnFinishCB)(RedisAI_OnFinishCtx ctx, void *private_data);
8486
* but only the fields needed in a given operation.
8587
*/
8688

87-
typedef struct RedisAI_RunInfo RedisAI_RunInfo;
88-
8989
struct RedisAI_RunInfo {
9090
RedisModuleBlockedClient *client;
9191
int single_op_dag;

src/tensor.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
#include "tensor.h"
1111
#include "err.h"
12+
#include "arr.h"
1213
#include "redisai.h"
14+
#include "version.h"
1315
#include "rmutil/alloc.h"
1416
#include "tensor_struct.h"
1517
#include "util/dict.h"

tests/flow/tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ valgrind_config() {
7979
#----------------------------------------------------------------------------------------------
8080

8181
run_tests() {
82+
make -C ../module
8283
local title="$1"
8384
[[ ! -z $title ]] && { $ROOT/opt/readies/bin/sep -0; printf "Tests with $title:\n\n"; }
8485
cd $ROOT/tests/flow

tests/flow/tests_llapi.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import redis
2+
3+
from includes import *
4+
import os
5+
6+
'''
7+
python -m RLTest --test tests_llapi.py --module path/to/redisai.so
8+
'''
9+
goal_dir = os.path.join(os.getcwd(), "../module/LLAPI.so")
10+
TEST_MODULE_PATH = os.path.abspath(goal_dir)
11+
12+
def test_basic_check(env):
13+
14+
con = env.getConnection()
15+
ret = con.execute_command("MODULE", "LOAD", TEST_MODULE_PATH)
16+
env.assertEqual(ret, b'OK')
17+
ret = con.execute_command("RAI_llapi.basic_check")
18+
env.assertEqual(ret, b'OK')

0 commit comments

Comments
 (0)