1set(JIT_TEST_ROOT ${TORCH_ROOT}/test/cpp/jit) 2 3# Build separate libraries the define custom classes/operators used from our Python tests. 4# These are intended to be used with torch.ops.load_library() in our Python test suite. 5add_library(torchbind_test SHARED 6 ${JIT_TEST_ROOT}/test_custom_class_registrations.h 7 ${JIT_TEST_ROOT}/test_custom_class_registrations.cpp 8) 9target_link_libraries(torchbind_test torch) 10 11add_library(jitbackend_test SHARED ${JIT_TEST_ROOT}/test_backend_lib.cpp) 12target_link_libraries(jitbackend_test torch) 13 14set(BACKEND_WITH_COMPILER_SRCS 15 ${JIT_TEST_ROOT}/test_backend_compiler_lib.cpp 16 ${JIT_TEST_ROOT}/test_backend_compiler_preprocess.cpp 17) 18if(USE_KINETO) 19 # Testing edge profiler for backend use 20 # profiler_edge should only be aded when USE_KINETO flag is on 21 list(APPEND BACKEND_WITH_COMPILER_SRCS 22 ${TORCH_SRC_DIR}/csrc/jit/mobile/profiler_edge.cpp) 23endif() 24 25add_library(backend_with_compiler SHARED 26 ${BACKEND_WITH_COMPILER_SRCS} 27 ) 28if(USE_KINETO) 29 set_target_properties(backend_with_compiler PROPERTIES COMPILE_FLAGS 30 "-DUSE_KINETO") 31endif() 32target_link_libraries(backend_with_compiler torch) 33 34if(INSTALL_TEST) 35 install(TARGETS torchbind_test DESTINATION lib) 36 install(TARGETS jitbackend_test DESTINATION lib) 37 install(TARGETS backend_with_compiler DESTINATION lib) 38endif() 39 40# Build the cpp gtest binary containing the cpp-only tests. 41set(JIT_TEST_SRCS 42 ${JIT_TEST_ROOT}/test_add_if_then_else.cpp 43 ${JIT_TEST_ROOT}/test_alias_analysis.cpp 44 ${JIT_TEST_ROOT}/test_argument_spec.cpp 45 ${JIT_TEST_ROOT}/test_autodiff.cpp 46 ${JIT_TEST_ROOT}/test_load_upgraders.cpp 47 ${JIT_TEST_ROOT}/test_op_replacement.cpp 48 ${JIT_TEST_ROOT}/test_upgrader_utils.cpp 49 ${JIT_TEST_ROOT}/test_backend.cpp 50 ${JIT_TEST_ROOT}/test_class_import.cpp 51 ${JIT_TEST_ROOT}/test_class_parser.cpp 52 ${JIT_TEST_ROOT}/test_class_type.cpp 53 ${JIT_TEST_ROOT}/test_code_template.cpp 54 ${JIT_TEST_ROOT}/test_concat_opt.cpp 55 ${JIT_TEST_ROOT}/test_constant_pooling.cpp 56 ${JIT_TEST_ROOT}/test_cleanup_passes.cpp 57 ${JIT_TEST_ROOT}/test_create_autodiff_subgraphs.cpp 58 ${JIT_TEST_ROOT}/test_custom_class.cpp 59 ${JIT_TEST_ROOT}/test_custom_class_registrations.h 60 ${JIT_TEST_ROOT}/test_custom_class_registrations.cpp 61 ${JIT_TEST_ROOT}/test_custom_operators.cpp 62 ${JIT_TEST_ROOT}/test_dce.cpp 63 ${JIT_TEST_ROOT}/test_fuser.cpp 64 ${JIT_TEST_ROOT}/test_graph_executor.cpp 65 ${JIT_TEST_ROOT}/test_graph_iterator.cpp 66 ${JIT_TEST_ROOT}/test_cs_debug_info_serialization.cpp 67 ${JIT_TEST_ROOT}/test_inliner.cpp 68 ${JIT_TEST_ROOT}/test_interface.cpp 69 ${JIT_TEST_ROOT}/test_interpreter.cpp 70 ${JIT_TEST_ROOT}/test_ir.cpp 71 ${JIT_TEST_ROOT}/test_irparser.cpp 72 ${JIT_TEST_ROOT}/test_jit_type.cpp 73 ${JIT_TEST_ROOT}/test_lite_interpreter.cpp 74 ${JIT_TEST_ROOT}/test_lite_interpreter_direct.cpp 75 ${JIT_TEST_ROOT}/test_lite_trainer.cpp 76 ${JIT_TEST_ROOT}/test_memory_dag.cpp 77 ${JIT_TEST_ROOT}/test_misc.cpp 78 ${JIT_TEST_ROOT}/test_mobile_type_parser.cpp 79 ${JIT_TEST_ROOT}/test_module_api.cpp 80 ${JIT_TEST_ROOT}/test_peephole_optimize.cpp 81 ${JIT_TEST_ROOT}/test_qualified_name.cpp 82 ${JIT_TEST_ROOT}/test_save_load.cpp 83 ${JIT_TEST_ROOT}/test_schema_info.cpp 84 ${JIT_TEST_ROOT}/test_schema_matching.cpp 85 ${JIT_TEST_ROOT}/test_stack_opt.cpp 86 ${JIT_TEST_ROOT}/test_subgraph_matcher.cpp 87 ${JIT_TEST_ROOT}/test_subgraph_rewriter.cpp 88 ${JIT_TEST_ROOT}/test_subgraph_utils.cpp 89 ${JIT_TEST_ROOT}/test_union.cpp 90 ${JIT_TEST_ROOT}/test_utils.cpp 91 ${JIT_TEST_ROOT}/test_script_profile.cpp 92 ${JIT_TEST_ROOT}/test_shape_analysis.cpp 93 ${JIT_TEST_ROOT}/test_jit_logging_levels.cpp 94 ${JIT_TEST_ROOT}/test_file_format.cpp 95 ${JIT_TEST_ROOT}/test_flatbuffer.cpp 96) 97 98add_executable(test_jit 99 ${TORCH_ROOT}/test/cpp/common/main.cpp 100 ${JIT_TEST_SRCS} 101) 102 103# We also build with UBSAN flag in build_asan.h 104if(USE_ASAN) 105 target_compile_options(test_jit PRIVATE "-fsanitize=undefined") 106 target_link_libraries(test_jit PRIVATE "-fsanitize=undefined") 107endif() 108 109target_link_libraries( 110 test_jit PRIVATE flatbuffers) 111 112 113# TODO temporary until we can delete the old gtest polyfills. 114target_compile_definitions(test_jit PRIVATE USE_GTEST) 115 116if(USE_SYSTEM_ONNX) 117 target_link_libraries(test_jit PRIVATE onnx_proto onnx) 118endif() 119 120if(USE_MKLDNN) 121 target_link_libraries(test_jit PRIVATE caffe2::mkldnn) 122endif() 123 124set(JIT_TEST_DEPENDENCIES torch gtest jitbackend_test backend_with_compiler) 125 126if(MSVC) 127 list(APPEND JIT_TEST_DEPENDENCIES onnx_library) 128endif(MSVC) 129 130target_link_libraries(test_jit PRIVATE ${JIT_TEST_DEPENDENCIES}) 131target_include_directories(test_jit PRIVATE ${ATen_CPU_INCLUDE}) 132 133if(LINUX) 134 #Update to target_link_options when CMake version can be upgraded 135 target_link_libraries(test_jit PRIVATE "-Wl,--no-as-needed,$<TARGET_FILE:jitbackend_test>,$<TARGET_FILE:backend_with_compiler>,--as-needed") 136endif() 137 138if(USE_CUDA) 139 target_compile_definitions(test_jit PRIVATE USE_CUDA) 140 # Suppress sign compare checks for NVFUSER JIT tests 141 if(NOT MSVC) 142 target_compile_options(test_jit PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wno-sign-compare>) 143 endif() 144elseif(USE_ROCM) 145 target_link_libraries(test_jit PRIVATE 146 ${ROCM_HIPRTC_LIB} 147 ${PYTORCH_HIP_LIBRARIES} 148 ${TORCH_CUDA_LIBRARIES}) 149 150 target_compile_definitions(test_jit PRIVATE USE_ROCM) 151endif() 152 153if(INSTALL_TEST) 154 install(TARGETS test_jit DESTINATION bin) 155 # Install PDB files for MSVC builds 156 if(MSVC AND BUILD_SHARED_LIBS) 157 install(FILES $<TARGET_PDB_FILE:test_jit> DESTINATION bin OPTIONAL) 158 endif() 159endif() 160