Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance bound check for shm offset #6914

Merged
merged 7 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for enhance bound check for shm offset
  • Loading branch information
kthui committed Feb 26, 2024
commit e921c12ac1a58421f1366263811ee3130d09e23a
27 changes: 24 additions & 3 deletions qa/L0_shared_memory/shared_memory_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2019-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -162,6 +162,7 @@ def _basic_inference(
error_msg,
big_shm_name="",
big_shm_size=64,
shm_output_offset=0,
):
input0_data = np.arange(start=0, stop=16, dtype=np.int32)
input1_data = np.ones(shape=16, dtype=np.int32)
Expand Down Expand Up @@ -191,8 +192,8 @@ def _basic_inference(
else:
inputs[1].set_shared_memory("input1_data", 64)

outputs[0].set_shared_memory("output0_data", 64)
outputs[1].set_shared_memory("output1_data", 64)
outputs[0].set_shared_memory("output0_data", 64, offset=shm_output_offset)
outputs[1].set_shared_memory("output1_data", 64, offset=shm_output_offset)

try:
results = triton_client.infer(
Expand Down Expand Up @@ -323,6 +324,26 @@ def test_unregisterall(self):
self.assertTrue(len(status_after.regions) == 0)
self._cleanup_server(shm_handles)

def test_infer_offset_out_of_bound(self):
# Shared memory offset outside output region - Throws error
rmccorm4 marked this conversation as resolved.
Show resolved Hide resolved
error_msg = []
shm_handles = self._configure_sever()
if _protocol == "http":
offset = 18446744073709551584 # -0x20 in int64_t
else:
offset = 9223372036854775807 # grpc will throw if > int64
self._basic_inference(
shm_handles[0],
shm_handles[1],
shm_handles[2],
shm_handles[3],
error_msg,
shm_output_offset=offset,
)
self.assertEqual(len(error_msg), 1)
self.assertIn("Invalid offset for shared memory region", error_msg[0])
self._cleanup_server(shm_handles)


if __name__ == "__main__":
_protocol = os.environ.get("CLIENT_TYPE", "http")
Expand Down
5 changes: 3 additions & 2 deletions qa/L0_shared_memory/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright 2019-2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright 2019-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -49,7 +49,8 @@ for i in \
test_register_after_inference \
test_too_big_shm \
test_mixed_raw_shm \
test_unregisterall; do
test_unregisterall \
test_infer_offset_out_of_bound; do
for client_type in http grpc; do
SERVER_ARGS="--model-repository=`pwd`/models --log-verbose=1 ${SERVER_ARGS_EXTRA}"
SERVER_LOG="./$i.$client_type.server.log"
Expand Down