Skip to content

Commit 778d829

Browse files
authored
LLAPI tests - fix deadlock (#710)
* - Fix dead-lock in llapi tests: need to acquire and release the lock in the "on-finish" callback to ensure that "on-finish" isn't done before the main-thread is waiting. - Refactor the RunResult_ctx in dag_utils to include the mutex and condition variable instead of having them global. * Add c-lang formatting (lint) for files in tests dir. * PR fix (only naming changes)
1 parent 4af01e8 commit 778d829

File tree

8 files changed

+407
-381
lines changed

8 files changed

+407
-381
lines changed

opt/clang-check-all.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
set -e
55

66
CLANG_FMT_SRCS=$(find ../src/ \( -name '*.c' -o -name '*.cc'-o -name '*.cpp' -o -name '*.h' -o -name '*.hh' -o -name '*.hpp' \))
7+
CLANG_FMT_TESTS=$(find ../tests/ \( -name '*.c' -o -name '*.cc'-o -name '*.cpp' -o -name '*.h' -o -name '*.hh' -o -name '*.hpp' \))
78

89
for filename in $CLANG_FMT_SRCS; do
910
echo "Checking $filename"
1011
clang-format -style=file -Werror --dry-run $filename
1112
done
13+
14+
for filename in $CLANG_FMT_TESTS; do
15+
echo "Checking $filename"
16+
clang-format -style=file -Werror --dry-run $filename
17+
done

opt/clang-format-all.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
set -e
55

66
CLANG_FMT_SRCS=$(find ../src/ \( -name '*.c' -o -name '*.cc'-o -name '*.cpp' -o -name '*.h' -o -name '*.hh' -o -name '*.hpp' \))
7+
CLANG_FMT_TESTS=$(find ../tests/ \( -name '*.c' -o -name '*.cc'-o -name '*.cpp' -o -name '*.h' -o -name '*.hh' -o -name '*.hpp' \))
78

89
for filename in $CLANG_FMT_SRCS; do
910
clang-format --verbose -style=file -i $filename
1011
done
12+
13+
for filename in $CLANG_FMT_TESTS; do
14+
clang-format --verbose -style=file -i $filename
15+
done

tests/flow/pt_api_test.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,41 @@
44
#include "dlpack/dlpack.h"
55

66
int main() {
7-
printf("Hello from libTorch C library version %s\n", "1.0");
8-
torchBasicTest();
7+
printf("Hello from libTorch C library version %s\n", "1.0");
8+
torchBasicTest();
99

10-
void* ctx;
11-
char *err = NULL;
10+
void *ctx;
11+
char *err = NULL;
1212

13-
const char script[] = "\n\
13+
const char script[] = "\n\
1414
def foo(a): \n\
1515
return a * 2 \n\
1616
";
1717

18-
ctx = torchCompileScript(script, kDLCPU, &err);
19-
if (err) {
20-
printf("ERR: %s\n", err);
21-
free(err);
22-
err = NULL;
23-
return 1;
24-
}
25-
printf("Compiled: %p\n", ctx);
18+
ctx = torchCompileScript(script, kDLCPU, &err);
19+
if (err) {
20+
printf("ERR: %s\n", err);
21+
free(err);
22+
err = NULL;
23+
return 1;
24+
}
25+
printf("Compiled: %p\n", ctx);
2626

27-
DLDataType dtype = (DLDataType){ .code = kDLFloat, .bits = 32, .lanes = 1};
28-
int64_t shape[1] = {1};
29-
int64_t strides[1] = {1};
30-
char data[4] = "0000";
31-
DLManagedTensor* input = torchNewTensor(dtype, 1, shape, strides, data);
32-
DLManagedTensor* output;
33-
torchRunScript(ctx, "foo", 1, &input, 1, &output, &err);
34-
if (err) {
35-
printf("ERR: %s\n", err);
36-
free(err);
37-
return 1;
38-
}
27+
DLDataType dtype = (DLDataType){.code = kDLFloat, .bits = 32, .lanes = 1};
28+
int64_t shape[1] = {1};
29+
int64_t strides[1] = {1};
30+
char data[4] = "0000";
31+
DLManagedTensor *input = torchNewTensor(dtype, 1, shape, strides, data);
32+
DLManagedTensor *output;
33+
torchRunScript(ctx, "foo", 1, &input, 1, &output, &err);
34+
if (err) {
35+
printf("ERR: %s\n", err);
36+
free(err);
37+
return 1;
38+
}
3939

40-
torchDeallocContext(ctx);
41-
printf("Deallocated\n");
40+
torchDeallocContext(ctx);
41+
printf("Deallocated\n");
4242

43-
return 0;
43+
return 0;
4444
}

tests/flow/tests_llapi.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ def test_dag_build_and_run(env):
101101
ret = con.execute_command("RAI_llapi.DAGrun")
102102
env.assertEqual(ret, b'DAG run success')
103103

104+
# Run the DAG LLAPI test again with multi process test to ensure that there are no dead-locks
105+
def run_dag_llapi(con):
106+
con.execute_command("RAI_llapi.DAGrun")
107+
108+
run_test_multiproc(env, 500, run_dag_llapi)
109+
104110

105111
@with_test_module
106112
def test_dagrun_multidevice_resnet(env):

tests/flow/tf_api_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
#include <tensorflow/c/c_api.h>
33

44
int main() {
5-
printf("Hello from TensorFlow C library version %s\n", TF_Version());
6-
return 0;
5+
printf("Hello from TensorFlow C library version %s\n", TF_Version());
6+
return 0;
77
}

0 commit comments

Comments
 (0)