diff --git a/test/py/CMakeLists.txt b/test/py/CMakeLists.txt index 634e6114520..b0662c9924f 100755 --- a/test/py/CMakeLists.txt +++ b/test/py/CMakeLists.txt @@ -1,7 +1,7 @@ ##################################################################################### # The MIT License (MIT) # -# Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved. +# Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -23,8 +23,14 @@ ##################################################################################### include(PythonModules) +set(VENV ${CMAKE_BINARY_DIR}/test/py/venv) +set(VENV_ONNX ${CMAKE_BINARY_DIR}/test/py/venv-onnx) +set(REQUIREMENTS ${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt) +set(REQUIREMENTS_ONNX ${CMAKE_CURRENT_SOURCE_DIR}/requirements-onnx.txt) +set(PYTHON_VERSION_TO_DISABLE_ONNX 3.6) -function(add_py_test NAME SCRIPT) + +function(add_py_venv_fixture FIXTURE_NAME VIRTUAL_ENV_DIR REQUIREMENTS_FILE) foreach(PYTHON_VERSION ${PYTHON_VERSIONS}) set (ENV_COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=$" @@ -32,28 +38,57 @@ function(add_py_test NAME SCRIPT) "MALLOC_CHECK_=3" ) set(PYTHON_EXECUTABLE ${PYTHON_${PYTHON_VERSION}_EXECUTABLE}) - add_test( - NAME test_py_${PYTHON_VERSION}_${NAME} - COMMAND ${ENV_COMMAND} ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT} ${ARGN}) - add_custom_target(test_py_${PYTHON_VERSION}_${NAME} - COMMAND ${ENV_COMMAND} ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT} ${ARGN} - COMMENT "${PYTHON_EXECUTABLE} ${SCRIPT}") + if(NOT TEST py_${PYTHON_VERSION}_${FIXTURE_NAME}_initialize_env) + if (NOT (${FIXTURE_NAME} STREQUAL "onnx" AND ${PYTHON_VERSION} STREQUAL ${PYTHON_VERSION_TO_DISABLE_ONNX})) + add_test(NAME py_${PYTHON_VERSION}_${FIXTURE_NAME}_initialize_env COMMAND ${PYTHON_EXECUTABLE} -m venv ${VIRTUAL_ENV_DIR}/${PYTHON_VERSION} --clear) + set_tests_properties(py_${PYTHON_VERSION}_${FIXTURE_NAME}_initialize_env PROPERTIES FIXTURES_SETUP ${FIXTURE_NAME}_${PYTHON_VERSION}_INIT_VENV) + set(PYTHON_EXECUTABLE ${VIRTUAL_ENV_DIR}/${PYTHON_VERSION}/bin/python) + add_test( + NAME py_${PYTHON_VERSION}_${FIXTURE_NAME}_setup_env + COMMAND ${PYTHON_EXECUTABLE} -m pip install -r ${REQUIREMENTS_FILE}) + set_tests_properties(py_${PYTHON_VERSION}_${FIXTURE_NAME}_setup_env PROPERTIES FIXTURES_REQUIRED ${FIXTURE_NAME}_${PYTHON_VERSION}_INIT_VENV) + set_tests_properties(py_${PYTHON_VERSION}_${FIXTURE_NAME}_setup_env PROPERTIES FIXTURES_SETUP ${FIXTURE_NAME}_${PYTHON_VERSION}_VENV) + endif() + endif() + endforeach() +endfunction() + +function(add_py_test NAME SCRIPT FIXTURE_NAME VENV_DIR) + foreach(PYTHON_VERSION ${PYTHON_VERSIONS}) + set (ENV_COMMAND ${CMAKE_COMMAND} -E env + "PYTHONPATH=$" + "PYTHONMALLOC=debug" + "MALLOC_CHECK_=3" + ) + set(PYTHON_EXECUTABLE ${VENV_DIR}/${PYTHON_VERSION}/bin/python) + if(NOT (${FIXTURE_NAME} STREQUAL "onnx" AND ${PYTHON_VERSION} STREQUAL ${PYTHON_VERSION_TO_DISABLE_ONNX})) + add_test( + NAME test_py_${PYTHON_VERSION}_${NAME} + COMMAND ${ENV_COMMAND} ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT} ${ARGN}) + set_tests_properties(test_py_${PYTHON_VERSION}_${NAME} PROPERTIES FIXTURES_REQUIRED ${FIXTURE_NAME}_${PYTHON_VERSION}_VENV) + add_custom_target(test_py_${PYTHON_VERSION}_${NAME} + COMMAND ${ENV_COMMAND} ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT} ${ARGN} + COMMENT "${PYTHON_EXECUTABLE} ${SCRIPT}") + endif() endforeach() endfunction() add_dependencies(tests migraphx_py) add_dependencies(check migraphx_py) -add_py_test(ref test_cpu.py WORKING_DIRECTORY ${TEST_ONNX_DIR}) -add_py_test(save_load test_save_load.py WORKING_DIRECTORY ${TEST_ONNX_DIR}) -add_py_test(op test_op.py WORKING_DIRECTORY ${TEST_ONNX_DIR}) -add_py_test(shape test_shape.py WORKING_DIRECTORY ${TEST_ONNX_DIR}) -add_py_test(module_construct test_module_construct.py WORKING_DIRECTORY ${TEST_ONNX_DIR}) -add_py_test(literal test_literal.py WORKING_DIRECTORY ${TEST_ONNX_DIR}) +add_py_venv_fixture(common ${VENV} ${REQUIREMENTS}) +add_py_venv_fixture(onnx ${VENV_ONNX} ${REQUIREMENTS_ONNX}) + +add_py_test(ref test_cpu.py common ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) +add_py_test(save_load test_save_load.py common ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) +add_py_test(op test_op.py common ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) +add_py_test(shape test_shape.py common ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) +add_py_test(module_construct test_module_construct.py common ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) +add_py_test(literal test_literal.py common ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) if(MIGRAPHX_ENABLE_GPU) -add_py_test(gpu_offload test_gpu_offload.py WORKING_DIRECTORY ${TEST_ONNX_DIR}) -add_py_test(gpu test_gpu.py WORKING_DIRECTORY ${TEST_ONNX_DIR}) -add_py_test(array test_array.py WORKING_DIRECTORY ${TEST_ONNX_DIR}) -add_py_test(backend onnx_backend_test.py WORKING_DIRECTORY ${TEST_ONNX_DIR}) -add_py_test(gpu_async test_gpu_async.py WORKING_DIRECTORY ${TEST_ONNX_DIR}) +add_py_test(gpu_offload test_gpu_offload.py common ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) +add_py_test(gpu test_gpu.py common ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) +add_py_test(array test_array.py common ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) +add_py_test(backend onnx_backend_test.py onnx ${VENV_ONNX} WORKING_DIRECTORY ${TEST_ONNX_DIR}) +add_py_test(gpu_async test_gpu_async.py common ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR}) endif() diff --git a/test/py/requirements-onnx.txt b/test/py/requirements-onnx.txt new file mode 100644 index 00000000000..fc6964ec664 --- /dev/null +++ b/test/py/requirements-onnx.txt @@ -0,0 +1,29 @@ +##################################################################################### +# The MIT License (MIT) +# +# Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +##################################################################################### + +onnx==1.14.1 +protobuf==3.20.2 +numpy==1.21.6 +packaging==23.0 +pytest==6.0.1 \ No newline at end of file diff --git a/test/py/requirements.txt b/test/py/requirements.txt new file mode 100644 index 00000000000..dda4d2dc228 --- /dev/null +++ b/test/py/requirements.txt @@ -0,0 +1,25 @@ +##################################################################################### +# The MIT License (MIT) +# +# Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +##################################################################################### + +numpy==1.21.6 \ No newline at end of file diff --git a/tools/install_prereqs.sh b/tools/install_prereqs.sh index 1deefb9a042..7ba0f37e181 100755 --- a/tools/install_prereqs.sh +++ b/tools/install_prereqs.sh @@ -3,7 +3,7 @@ ##################################################################################### # The MIT License (MIT) # -# Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved. +# Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -51,6 +51,7 @@ else openmp-extras \ python3-dev \ python3-pip \ + python3-venv \ rocblas-dev \ rocm-cmake fi