|
2 | 2 | import sys
|
3 | 3 | import os
|
4 | 4 | import subprocess
|
| 5 | +import psutil |
5 | 6 | import redis
|
6 | 7 | from includes import *
|
7 | 8 | from RLTest import Env
|
@@ -554,6 +555,45 @@ def test_multiple_devices(self):
|
554 | 555 | self.env.assertEqual(backends_info['ai_onnxruntime_maximum_run_sessions_number'],
|
555 | 556 | str(len(devices)*self.threads_per_queue))
|
556 | 557 |
|
| 558 | + # Stress test to validate that we have no race condition between the creation of the onnx global array (from |
| 559 | + # the main threads) that contains an entry for every worker thread, and the background thread that runs the |
| 560 | + # session and access this global array. |
| 561 | + def test_synchronization(self): |
| 562 | + if self.env.isCluster() or self.env.useSlaves or VALGRIND == 1: |
| 563 | + self.env.debugPrint("skipping {} on cluster/slaves/valgrind modes".format(sys._getframe().f_code.co_name), force=True) |
| 564 | + return |
| 565 | + |
| 566 | + model_pb = load_file_content('mul_1.onnx') |
| 567 | + |
| 568 | + def launch_redis_and_run_onnx(con, proc_id, pipes): |
| 569 | + my_pipe = pipes[proc_id] |
| 570 | + port = 6380 + proc_id # Let every subprocess run on a fresh port. |
| 571 | + redis_server = subprocess.Popen(['redis-server', '--port', str(port), |
| 572 | + '--loadmodule', f'{ROOT}/install-{DEVICE.lower()}/redisai.so', |
| 573 | + '--logfile', f'{self.env.logDir}/test_onnx_kill_switch_synchronization-{port}.log', |
| 574 | + '--dir', f'{self.env.logDir}', |
| 575 | + '--dbfilename', f'test_onnx_kill_switch_synchronization-{port}.rdb']) |
| 576 | + # Wait until redis-server is up and ready to accept connections. |
| 577 | + while len([c for c in psutil.net_connections("tcp") |
| 578 | + if c.pid == redis_server.pid and c.laddr.port == port]) == 0: |
| 579 | + time.sleep(1) |
| 580 | + # Create a connection to Redis that immediately loads and execute onnx model. This is for testing that |
| 581 | + # there was a proper synchronization - otherwise, execution might cause a server crash. |
| 582 | + r = redis.Redis(host='localhost', port=port) |
| 583 | + r.flushall() |
| 584 | + r.execute_command('AI.MODELSTORE', 'mul{1}', 'ONNX', 'CPU', 'BLOB', model_pb) |
| 585 | + r.execute_command('AI.TENSORSET', 'a{1}', 'FLOAT', 3, 2, 'VALUES', 1.0, 2.0, 3.0, 4.0, 5.0, 6.0) |
| 586 | + r.execute_command('AI.MODELEXECUTE', 'mul{1}', 'INPUTS', 1, 'a{1}', 'OUTPUTS', 1, 'b{1}') |
| 587 | + my_pipe.send(1) # To indicate that the flow was executed with success. |
| 588 | + redis_server.kill() |
| 589 | + |
| 590 | + num_parallel_clients = 50 |
| 591 | + parent_end_pipes, children_end_pipes = get_parent_children_pipes(num_parallel_clients) |
| 592 | + run_test_multiproc(self.env, '{1}', num_parallel_clients, launch_redis_and_run_onnx, |
| 593 | + args=(children_end_pipes, )) |
| 594 | + # Assert that all sub-processes have finished successfully. |
| 595 | + self.env.assertEqual(sum([p.recv() for p in parent_end_pipes]), num_parallel_clients) |
| 596 | + |
557 | 597 |
|
558 | 598 | def test_forbidden_external_initializers(env):
|
559 | 599 | if not TEST_ONNX:
|
|
0 commit comments