Skip to content

Commit 13dfd20

Browse files
author
DvirDukhan
authored
Merge branch 'master' into torchscript_extensions
2 parents 4f0b31b + 1584548 commit 13dfd20

File tree

17 files changed

+160
-63
lines changed

17 files changed

+160
-63
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ platform-build-defs: &platform-build-defs
331331

332332
after-platform-builds: &after-platform-builds
333333
requires:
334-
- build-centos7
334+
# - build-centos7
335335
- build-bionic
336336
- build-xenial
337337

@@ -358,7 +358,7 @@ workflows:
358358
- platform-build:
359359
name: build-xenial
360360
platform: xenial
361-
<<: *on-any-branch
361+
<<: *platform-build-defs
362362
- coverage:
363363
<<: *on-any-branch
364364
<<: *after-linter

opt/system-setup.py

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import argparse
66

77
HERE = os.path.abspath(os.path.dirname(__file__))
8+
READIES = os.path.join(HERE, "readies")
89
ROOT = os.path.abspath(os.path.join(HERE, ".."))
9-
sys.path.insert(0, os.path.join(HERE, "readies"))
10+
sys.path.insert(0, READIES)
1011
import paella
1112

1213
#----------------------------------------------------------------------------------------------
@@ -19,9 +20,6 @@ def common_first(self):
1920
self.install_downloaders()
2021
self.setup_pip()
2122
self.pip_install("wheel virtualenv")
22-
# if self.osnick == 'xenial':
23-
# self.pip_install("setuptools --upgrade")
24-
# self.pip_install("-IU --force-reinstall setuptools")
2523

2624
if self.os == 'linux':
2725
self.install("ca-certificates")
@@ -32,17 +30,6 @@ def debian_compat(self):
3230
self.install("gawk")
3331
self.install("build-essential")
3432
self.install("libssl-dev")
35-
self.run("""
36-
apt remove -y --purge --auto-remove cmake
37-
version=3.19
38-
build=0
39-
mkdir ~/temp
40-
cd ~/temp
41-
wget https://cmake.org/files/v$version/cmake-$version.$build-Linux-x86_64.sh
42-
mkdir /opt/cmake
43-
sh cmake-$version.$build-Linux-x86_64.sh --prefix=/opt/cmake --skip-license
44-
ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
45-
""")
4633
self.install("clang-format")
4734
self.install("python3-regex")
4835
self.install("python3-psutil python3-networkx python3-numpy") # python3-skimage
@@ -53,22 +40,11 @@ def redhat_compat(self):
5340
self.run("%s/readies/bin/enable-utf8" % HERE)
5441

5542
self.group_install("'Development Tools'")
56-
57-
self.install("centos-release-scl")
58-
self.install("devtoolset-8")
59-
self.run("cp /opt/rh/devtoolset-8/enable /etc/profile.d/scl-devtoolset-8.sh")
60-
43+
self.run("%s/bin/getgcc --modern" % READIES)
6144
self.install("llvm-toolset-7")
6245

63-
paella.mkdir_p("%s/profile.d" % ROOT)
64-
self.run("cp /opt/rh/devtoolset-8/enable %s/profile.d/scl-devtoolset-8.sh" % ROOT)
65-
66-
self.run("""
67-
dir=$(mktemp -d /tmp/tar.XXXXXX)
68-
(cd $dir; wget -q -O tar.tgz http://redismodules.s3.amazonaws.com/gnu/gnu-tar-1.32-x64-centos7.tgz; tar -xzf tar.tgz -C /; )
69-
rm -rf $dir
70-
""")
71-
46+
if self.arch == 'x64':
47+
self.install_linux_gnu_tar()
7248

7349
if not self.dist == "amzn":
7450
self.install("epel-release")
@@ -79,30 +55,23 @@ def redhat_compat(self):
7955
self.install("python3-devel")
8056
self.pip_install("psutil")
8157

82-
self.install("cmake3")
83-
self.run("ln -sf `command -v cmake3` /usr/local/bin/cmake")
84-
8558
self.install_git_lfs_on_linux()
8659

8760
def fedora(self):
8861
self.group_install("'Development Tools'")
89-
self.install("cmake")
90-
self.run("ln -sf `command -v cmake3` /usr/local/bin/cmake")
9162
self.install("python3 python3-psutil python3-networkx")
9263
self.install("clang")
9364
self.install_git_lfs_on_linux()
9465

9566
def macos(self):
96-
if sh('xcode-select -p') == '':
97-
fatal("Xcode tools are not installed. Please run xcode-select --install.")
98-
9967
self.install_gnu_utils()
100-
self.install("cmake")
10168
self.install("git-lfs")
10269
self.install("redis")
10370
self.install("clang-format")
10471

10572
def common_last(self):
73+
self.run("%s/bin/getcmake" % READIES)
74+
10675
self.run("python3 -m pip uninstall -y ramp-packer RLTest || true")
10776
# redis-py-cluster should be installed from git due to redis-py dependency
10877
self.pip_install("--no-cache-dir git+https://github.com/Grokzen/redis-py-cluster.git@master")

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.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2+
#ifdef __linux__
3+
#define _GNU_SOURCE
4+
#endif
5+
16
#define REDISMODULE_MAIN
27
#include "redismodule.h"
38
#include "tensor.h"
@@ -32,6 +37,12 @@
3237
#define REDISAI_GIT_SHA "unknown"
3338
#endif
3439

40+
#ifdef __linux__
41+
#ifndef RUSAGE_THREAD
42+
#define RUSAGE_THREAD 1
43+
#endif
44+
#endif
45+
3546
int redisMajorVersion;
3647
int redisMinorVersion;
3748
int redisPatchVersion;
@@ -986,10 +997,31 @@ void RAI_moduleInfoFunc(RedisModuleInfoCtx *ctx, int for_crash_report) {
986997
RedisModule_InfoAddFieldLongLong(ctx, "inter_op_parallelism", getBackendsInterOpParallelism());
987998
RedisModule_InfoAddFieldLongLong(ctx, "intra_op_parallelism", getBackendsIntraOpParallelism());
988999
struct rusage self_ru, c_ru;
1000+
9891001
// Return resource usage statistics for the calling process,
9901002
// which is the sum of resources used by all threads in the
9911003
// process
9921004
getrusage(RUSAGE_SELF, &self_ru);
1005+
1006+
// Return resource usage statistics for the calling thread
1007+
// which in this case is Redis/RedisAI main thread
1008+
// RUSAGE_THREAD is Linux-specific.
1009+
sds main_thread_used_cpu_sys = sdsempty();
1010+
sds main_thread_used_cpu_user = sdsempty();
1011+
#if (defined(__linux__) && defined(RUSAGE_THREAD))
1012+
struct rusage main_thread_ru;
1013+
getrusage(RUSAGE_THREAD, &main_thread_ru);
1014+
main_thread_used_cpu_sys =
1015+
sdscatprintf(main_thread_used_cpu_sys, "%ld.%06ld", (long)main_thread_ru.ru_stime.tv_sec,
1016+
(long)self_ru.ru_stime.tv_usec);
1017+
main_thread_used_cpu_user =
1018+
sdscatprintf(main_thread_used_cpu_user, "%ld.%06ld", (long)main_thread_ru.ru_utime.tv_sec,
1019+
(long)self_ru.ru_utime.tv_usec);
1020+
#else
1021+
sdscatprintf(main_thread_used_cpu_sys, "N/A");
1022+
sdscatprintf(main_thread_used_cpu_user, "N/A");
1023+
#endif
1024+
9931025
// Return resource usage statistics for all of its
9941026
// terminated child processes
9951027
getrusage(RUSAGE_CHILDREN, &c_ru);
@@ -1006,6 +1038,8 @@ void RAI_moduleInfoFunc(RedisModuleInfoCtx *ctx, int for_crash_report) {
10061038
RedisModule_InfoAddFieldCString(ctx, "self_used_cpu_user", self_used_cpu_user);
10071039
RedisModule_InfoAddFieldCString(ctx, "children_used_cpu_sys", children_used_cpu_sys);
10081040
RedisModule_InfoAddFieldCString(ctx, "children_used_cpu_user", children_used_cpu_user);
1041+
RedisModule_InfoAddFieldCString(ctx, "main_thread_used_cpu_sys", main_thread_used_cpu_sys);
1042+
RedisModule_InfoAddFieldCString(ctx, "main_thread_used_cpu_user", main_thread_used_cpu_user);
10091043

10101044
AI_dictIterator *iter = AI_dictGetSafeIterator(run_queues);
10111045
AI_dictEntry *entry = AI_dictNext(iter);
@@ -1018,7 +1052,7 @@ void RAI_moduleInfoFunc(RedisModuleInfoCtx *ctx, int for_crash_report) {
10181052
struct timespec ts;
10191053
clockid_t cid;
10201054
sds queue_used_cpu_total = sdscatprintf(
1021-
sdsempty(), "queue_%s_bthread_#%d_used_cpu_total", queue_name, i + 1);
1055+
sdsempty(), "queue_%s_bthread_n%d_used_cpu_total", queue_name, i + 1);
10221056
sds bthread_used_cpu_total = sdsempty();
10231057
#if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || defined(_DARWIN_C_SOURCE) || \
10241058
defined(__cplusplus)
@@ -1034,7 +1068,7 @@ void RAI_moduleInfoFunc(RedisModuleInfoCtx *ctx, int for_crash_report) {
10341068
} else {
10351069
bthread_used_cpu_total =
10361070
sdscatprintf(bthread_used_cpu_total, "%ld.%06ld", (long)ts.tv_sec,
1037-
(long)(ts.tv_nsec / 1000000));
1071+
(long)(ts.tv_nsec / 1000));
10381072
}
10391073
}
10401074
RedisModule_InfoAddFieldCString(ctx, queue_used_cpu_total, bthread_used_cpu_total);

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

0 commit comments

Comments
 (0)