Skip to content

Commit

Permalink
Address comments to create virtual env for all python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsan-ca committed Sep 22, 2023
1 parent c8131e1 commit 00c01be
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 35 deletions.
79 changes: 44 additions & 35 deletions test/py/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,71 @@
#####################################################################################

include(PythonModules)
set(FIX_NAME SETUP_VIRTUAL_ENV)
set(VENV_DIR ${CMAKE_BINARY_DIR}/test/py/venv)
set(VENV ${CMAKE_BINARY_DIR}/test/py/venv)

function(add_py_venv_fixture FIXTURE_NAME VIRTUAL_ENV_DIR REQUIREMENTS_FILE)
message("Attempting to create virtual environment: ${VIRTUAL_ENV_DIR}")
find_package (Python3 COMPONENTS Interpreter)
add_test (NAME INITIALIZE_VENV COMMAND "${Python3_EXECUTABLE}" -m venv ${VIRTUAL_ENV_DIR})
set_tests_properties(INITIALIZE_VENV PROPERTIES FIXTURES_SETUP INIT_VENV)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
file(READ "/etc/os-release" OS_RELEASE_CONTENTS)
if(OS_RELEASE_CONTENTS MATCHES "ID=\"sles\"")
message("This is SUSE Linux Enterprise Server.")
set(REQUIREMENTS ${CMAKE_CURRENT_SOURCE_DIR}/requirements-sles.txt)
else()
message("This is NOT SUSE Linux Enterprise Server.")
set(REQUIREMENTS ${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt)
endif()
endif()

set (ENV{VIRTUAL_ENV} ${VIRTUAL_ENV_DIR})
set (Python3_FIND_VIRTUALENV ONLY)
unset (Python3_EXECUTABLE)
find_package (Python3 COMPONENTS Interpreter Development)
add_test (NAME SETUP_VENV COMMAND "${Python3_EXECUTABLE}" -m pip install -r ${REQUIREMENTS_FILE})
set_tests_properties(SETUP_VENV PROPERTIES FIXTURES_REQUIRED INIT_VENV)
set_tests_properties(SETUP_VENV PROPERTIES FIXTURES_SETUP ${FIXTURE_NAME})
function(add_py_venv_fixture VENV_DIR REQUIREMENTS_FILE)
foreach(PYTHON_VERSION ${PYTHON_VERSIONS})
set (ENV_COMMAND ${CMAKE_COMMAND} -E env
"PYTHONPATH=$<TARGET_FILE_DIR:migraphx_pybind_${PYTHON_VERSION}>"
"PYTHONMALLOC=debug"
"MALLOC_CHECK_=3"
)
set(PYTHON_EXECUTABLE ${PYTHON_${PYTHON_VERSION}_EXECUTABLE})
set(VIRTUAL_ENV_DIR ${VENV_DIR}/${PYTHON_VERSION})

add_test(NAME py_${PYTHON_VERSION}_initialize_env COMMAND ${PYTHON_EXECUTABLE} -m venv ${VIRTUAL_ENV_DIR} --clear)
set_tests_properties(py_${PYTHON_VERSION}_initialize_env PROPERTIES FIXTURES_SETUP ${PYTHON_VERSION}_INIT_VENV)
set(ENV{VIRTUAL_ENV} ${VIRTUAL_ENV_DIR})
set(PYTHON_EXECUTABLE ${VIRTUAL_ENV_DIR}/bin/python)
add_test(NAME py_${PYTHON_VERSION}_setup_env COMMAND ${PYTHON_EXECUTABLE} -m pip install -r ${REQUIREMENTS_FILE})
set_tests_properties(py_${PYTHON_VERSION}_setup_env PROPERTIES FIXTURES_REQUIRED ${PYTHON_VERSION}_INIT_VENV)
set_tests_properties(py_${PYTHON_VERSION}_setup_env PROPERTIES FIXTURES_SETUP ${PYTHON_VERSION}_VENV)
endforeach()
endfunction()

function(add_py_test NAME SCRIPT)
function(add_py_test NAME SCRIPT VENV_DIR)
foreach(PYTHON_VERSION ${PYTHON_VERSIONS})
set (ENV_COMMAND ${CMAKE_COMMAND} -E env
"PYTHONPATH=$<TARGET_FILE_DIR:migraphx_pybind_${PYTHON_VERSION}>"
"PYTHONMALLOC=debug"
"MALLOC_CHECK_=3"
)
set (ENV{VIRTUAL_ENV} ${VENV_DIR})
set (Python3_FIND_VIRTUALENV ONLY)
unset (Python3_EXECUTABLE)
find_package (Python3 COMPONENTS Interpreter Development)
set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}")
set(PYTHON_EXECUTABLE ${VENV_DIR}/${PYTHON_VERSION}/bin/python)
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 ${FIX_NAME})
set_tests_properties(test_py_${PYTHON_VERSION}_${NAME} PROPERTIES FIXTURES_REQUIRED ${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}")

endforeach()
endfunction()
add_dependencies(tests migraphx_py)
add_dependencies(check migraphx_py)

add_py_venv_fixture(
${FIX_NAME} ${VENV_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/REQUIREMENTS.TXT)
add_py_venv_fixture(${VENV} ${REQUIREMENTS})

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_test(ref test_cpu.py ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR})
add_py_test(save_load test_save_load.py ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR})
add_py_test(op test_op.py ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR})
add_py_test(shape test_shape.py ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR})
add_py_test(module_construct test_module_construct.py ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR})
add_py_test(literal test_literal.py ${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 ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR})
add_py_test(gpu test_gpu.py ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR})
add_py_test(array test_array.py ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR})
add_py_test(backend onnx_backend_test.py ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR})
add_py_test(gpu_async test_gpu_async.py ${VENV} WORKING_DIRECTORY ${TEST_ONNX_DIR})
endif()
Empty file added test/py/requirements-sles.txt
Empty file.
File renamed without changes.

0 comments on commit 00c01be

Please sign in to comment.