Skip to content

Commit 8f92cd8

Browse files
authored
Merge branch 'OnnxRuntime_set_allocator' into ck-dockerisms
2 parents 3d7be97 + eac91a1 commit 8f92cd8

File tree

11 files changed

+32
-66
lines changed

11 files changed

+32
-66
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ ENDIF()
200200
#----------------------------------------------------------------------------------------------
201201

202202
ADD_SUBDIRECTORY(src)
203+
ADD_SUBDIRECTORY(tests/module)
203204
ADD_LIBRARY(redisai SHARED $<TARGET_OBJECTS:redisai_obj>)
204205

205206
TARGET_LINK_LIBRARIES(redisai ${CMAKE_DL_LIBS})

opt/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ test: build
276276
$(SHOW)\
277277
DEVICE=$(DEVICE) \
278278
MODULE=$(realpath $(INSTALLED_TARGET)) \
279+
TESTMOD=$(realpath $(BINDIR)/tests/module/testmod.so) \
279280
CLUSTER=$(CLUSTER) \
280281
GEN=$(GEN) AOF=$(AOF) SLAVES=$(SLAVES) \
281282
VALGRIND=$(VALGRIND) \

opt/build/onnxruntime/Dockerfile.x64

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ RUN apt-get install -y locales && \
2424

2525
WORKDIR /build
2626

27-
ARG BUILDTYPE=MinSizeRel
27+
28+
ARG BUILDTYPE=RelWithDebInfo
2829
ARG BUILDARGS="--config ${BUILDTYPE} --parallel"
2930

3031
RUN git clone --single-branch --branch rel-${ONNXRUNTIME_VER} ${ONNXRUNTIME_REPO} onnxruntime

opt/build/onnxruntime/pack.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ VER="$1"
55
PLATFORM="$2"
66

77
mkdir -p pack/include pack/lib
8-
cp onnxruntime/build/Linux/MinSizeRel/libonnxruntime.so.${VER} pack/lib/
8+
cp onnxruntime/build/Linux/RelWithDebInfo/libonnxruntime.so.${VER} pack/lib/
99
cp onnxruntime/docs/C_API.md pack/
1010
cp onnxruntime/LICENSE pack/
1111
cp onnxruntime/README.md pack/

src/backends/onnxruntime.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,13 @@ RAI_Model *RAI_ModelCreateORT(RAI_Backend backend, const char *devicestr, RAI_Mo
320320
}
321321

322322
ONNX_VALIDATE_STATUS(ort->CreateSessionOptions(&session_options))
323-
324-
#ifndef RAI_ONNXRUNTIME_USE_CUDA
325-
// These are required to ensure that onnx will use the registered REDIS allocator (for
326-
// a model that defined to run on CPU).
327-
ONNX_VALIDATE_STATUS(
328-
ort->AddSessionConfigEntry(session_options, "session.use_env_allocators", "1"))
329-
ONNX_VALIDATE_STATUS(ort->DisableCpuMemArena(session_options))
330-
#endif
323+
if (strcasecmp(devicestr, "CPU") == 0) {
324+
// These are required to ensure that onnx will use the registered REDIS allocator (for
325+
// a model that defined to run on CPU).
326+
ONNX_VALIDATE_STATUS(
327+
ort->AddSessionConfigEntry(session_options, "session.use_env_allocators", "1"))
328+
ONNX_VALIDATE_STATUS(ort->DisableCpuMemArena(session_options))
329+
}
331330

332331
// TODO: these options could be configured at the AI.CONFIG level
333332
ONNX_VALIDATE_STATUS(ort->SetSessionGraphOptimizationLevel(session_options, 1))

tests/flow/includes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import paella
1616

1717
ROOT = os.environ.get("ROOT", None)
18+
TESTMOD_PATH = os.environ.get("TESTMOD", None)
1819
MAX_ITERATIONS = 2 if os.environ.get("MAX_ITERATIONS") == None else os.environ.get("MAX_ITERATIONS")
1920
TEST_TF = os.environ.get("TEST_TF") != "0" and os.environ.get("WITH_TF") != "0"
2021
TEST_TFLITE = os.environ.get("TEST_TFLITE") != "0" and os.environ.get("WITH_TFLITE") != "0"

tests/flow/tests.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ help() {
2828
Argument variables:
2929
VERBOSE=1 Print commands
3030
IGNERR=1 Do not abort on error
31+
32+
MODULE=path Path to redisai.so
33+
TESTMOD=path Path to LLAPI module
3134
3235
DEVICE=cpu|gpu Device for testing
3336
GEN=0|1 General tests
@@ -92,7 +95,6 @@ valgrind_summary() {
9295
#----------------------------------------------------------------------------------------------
9396

9497
run_tests() {
95-
make -C ../module
9698
local title="$1"
9799
[[ ! -z $title ]] && { $ROOT/opt/readies/bin/sep -0; printf "Tests with $title:\n\n"; }
98100
cd $ROOT/tests/flow
@@ -116,6 +118,8 @@ OP=""
116118

117119
MODULE=${MODULE:-$1}
118120
[[ -z $MODULE || ! -f $MODULE ]] && { echo "Module not found at ${MODULE}. Aborting."; exit 1; }
121+
TESTMOD=${TESTMOD}
122+
echo "Test module path is ${TESTMOD}"
119123

120124
[[ $VALGRIND == 1 || $VGD == 1 ]] && valgrind_config
121125

tests/flow/tests_llapi.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@
88
python -m RLTest --test tests_llapi.py --module path/to/redisai.so
99
'''
1010

11-
12-
def ensure_test_module_loaded(f):
11+
def with_test_module(f):
1312
@wraps(f)
1413
def wrapper(env, *args, **kwargs):
15-
goal_dir = os.path.join(os.path.dirname(__file__), "../module/LLAPI.so")
16-
TEST_MODULE_PATH = os.path.abspath(goal_dir)
1714
con = env.getConnection()
1815
modules = con.execute_command("MODULE", "LIST")
1916
if b'RAI_llapi' in [module[1] for module in modules]:
2017
return f(env, *args, **kwargs)
2118
try:
22-
ret = con.execute_command('MODULE', 'LOAD', TEST_MODULE_PATH)
19+
ret = con.execute_command('MODULE', 'LOAD', TESTMOD_PATH)
2320
env.assertEqual(ret, b'OK')
2421
except Exception as e:
2522
env.assertFalse(True)
@@ -29,15 +26,15 @@ def wrapper(env, *args, **kwargs):
2926
return wrapper
3027

3128

32-
@ensure_test_module_loaded
29+
@with_test_module
3330
def test_basic_check(env):
3431

3532
con = env.getConnection()
3633
ret = con.execute_command("RAI_llapi.basic_check")
3734
env.assertEqual(ret, b'OK')
3835

3936

40-
@ensure_test_module_loaded
37+
@with_test_module
4138
def test_model_run_async(env):
4239

4340
con = env.getConnection()
@@ -56,7 +53,7 @@ def test_model_run_async(env):
5653
env.assertEqual(ret, b'Async run success')
5754

5855

59-
@ensure_test_module_loaded
56+
@with_test_module
6057
def test_script_run_async(env):
6158

6259
con = env.getConnection()
@@ -78,7 +75,7 @@ def test_script_run_async(env):
7875
env.assertEqual(ret, b'Async run success')
7976

8077

81-
@ensure_test_module_loaded
78+
@with_test_module
8279
def test_dag_build_and_run(env):
8380
con = env.getConnection()
8481

@@ -105,7 +102,7 @@ def test_dag_build_and_run(env):
105102
env.assertEqual(ret, b'DAG run success')
106103

107104

108-
@ensure_test_module_loaded
105+
@with_test_module
109106
def test_dagrun_multidevice_resnet(env):
110107
con = env.getConnection()
111108

tests/flow/tests_onnx.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def test_onnx_modelrun_mnist(env):
1616
return
1717

1818
con = env.getConnection()
19-
2019
test_data_path = os.path.join(os.path.dirname(__file__), 'test_data')
2120
model_filename = os.path.join(test_data_path, 'mnist.onnx')
2221
wrong_model_filename = os.path.join(test_data_path, 'graph.pb')
@@ -458,9 +457,6 @@ def test_onnx_use_custom_allocator(env):
458457
if not TEST_ONNX:
459458
env.debugPrint("skipping {} since TEST_ONNX=0".format(sys._getframe().f_code.co_name), force=True)
460459
return
461-
if DEVICE != 'CPU':
462-
env.debugPrint("skipping {} since the custom allocator is for CPU".format(sys._getframe().f_code.co_name), force=True)
463-
return
464460

465461
con = env.getConnection()
466462
test_data_path = os.path.join(os.path.dirname(__file__), 'test_data')
@@ -472,7 +468,7 @@ def test_onnx_use_custom_allocator(env):
472468
env.assertEqual(int(ai_memory_config["ai_onnxruntime_memory"]), 0)
473469

474470
# Expect using the allocator during model set for allocating the model, its input name and output name.
475-
ret = con.execute_command('AI.MODELSET', 'm{1}', 'ONNX', DEVICE, 'BLOB', model_pb)
471+
ret = con.execute_command('AI.MODELSET', 'm{1}', 'ONNX', 'CPU', 'BLOB', model_pb)
476472
env.assertEqual(ret, b'OK')
477473
ai_memory_config = {k.split(":")[0]: k.split(":")[1]
478474
for k in con.execute_command("INFO MODULES").decode().split("#")[4].split()[1:]}
@@ -496,7 +492,7 @@ def test_onnx_use_custom_allocator(env):
496492
with open(sample_filename, 'rb') as f:
497493
sample_raw = f.read()
498494

499-
ret = con.execute_command('AI.MODELSET', 'm{1}', 'ONNX', DEVICE, 'BLOB', model_pb)
495+
ret = con.execute_command('AI.MODELSET', 'm{1}', 'ONNX', 'CPU', 'BLOB', model_pb)
500496
env.assertEqual(ret, b'OK')
501497
con.execute_command('AI.TENSORSET', 'a{1}', 'FLOAT', 1, 1, 28, 28, 'BLOB', sample_raw)
502498

tests/module/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ADD_LIBRARY(testmod SHARED LLAPI.c DAG_utils.c)
2+
3+
INCLUDE_DIRECTORIES(../../src)
4+
SET_TARGET_PROPERTIES(testmod PROPERTIES PREFIX "")
5+
SET_TARGET_PROPERTIES(testmod PROPERTIES SUFFIX ".so")

0 commit comments

Comments
 (0)