xref: /aosp_15_r20/external/pytorch/test/cpp/tensorexpr/CMakeLists.txt (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1set(TENSOREXPR_TEST_ROOT ${TORCH_ROOT}/test/cpp/tensorexpr)
2
3set(TENSOREXPR_TEST_SRCS
4  ${TENSOREXPR_TEST_ROOT}/test_approx.cpp
5  ${TENSOREXPR_TEST_ROOT}/test_aten.cpp
6  ${TENSOREXPR_TEST_ROOT}/test_boundsinference.cpp
7  ${TENSOREXPR_TEST_ROOT}/test_conv.cpp
8  ${TENSOREXPR_TEST_ROOT}/test_cpp_codegen.cpp
9  ${TENSOREXPR_TEST_ROOT}/test_dynamic_shapes.cpp
10  ${TENSOREXPR_TEST_ROOT}/test_expr.cpp
11  ${TENSOREXPR_TEST_ROOT}/test_external_calls.cpp
12  ${TENSOREXPR_TEST_ROOT}/test_graph_opt.cpp
13  ${TENSOREXPR_TEST_ROOT}/test_ir_printer.cpp
14  ${TENSOREXPR_TEST_ROOT}/test_ir_verifier.cpp
15  ${TENSOREXPR_TEST_ROOT}/test_kernel.cpp
16  ${TENSOREXPR_TEST_ROOT}/test_loopnest.cpp
17  ${TENSOREXPR_TEST_ROOT}/test_memdependency.cpp
18  ${TENSOREXPR_TEST_ROOT}/test_ops.cpp
19  ${TENSOREXPR_TEST_ROOT}/test_quantization.cpp
20  ${TENSOREXPR_TEST_ROOT}/test_memplanning.cpp
21  ${TENSOREXPR_TEST_ROOT}/test_reductions.cpp
22  ${TENSOREXPR_TEST_ROOT}/test_registerizer.cpp
23  ${TENSOREXPR_TEST_ROOT}/test_simplify.cpp
24  ${TENSOREXPR_TEST_ROOT}/test_te_fuser_pass.cpp
25  ${TENSOREXPR_TEST_ROOT}/test_type.cpp
26  ${TENSOREXPR_TEST_ROOT}/test_type_specializations.cpp
27)
28
29if(USE_CUDA)
30  list(APPEND TENSOREXPR_TEST_SRCS ${TENSOREXPR_TEST_ROOT}/test_cuda.cpp)
31endif()
32
33if(USE_LLVM AND LLVM_FOUND)
34  list(APPEND TENSOREXPR_TEST_SRCS ${TENSOREXPR_TEST_ROOT}/test_llvm.cpp)
35endif()
36
37add_executable(test_tensorexpr
38  ${TORCH_ROOT}/test/cpp/common/main.cpp
39  ${TENSOREXPR_TEST_ROOT}/padded_buffer.cpp
40  ${TENSOREXPR_TEST_SRCS})
41
42target_link_libraries(test_tensorexpr PRIVATE torch gtest)
43target_include_directories(test_tensorexpr PRIVATE ${ATen_CPU_INCLUDE})
44target_compile_definitions(test_tensorexpr PRIVATE USE_GTEST)
45
46add_executable(tutorial_tensorexpr ${TENSOREXPR_TEST_ROOT}/tutorial.cpp)
47target_link_libraries(tutorial_tensorexpr PRIVATE torch)
48target_include_directories(tutorial_tensorexpr PRIVATE ${ATen_CPU_INCLUDE})
49
50# The test case depends on the xnnpack header which in turn depends on the
51# pthreadpool header. For some build environment we need add the dependency
52# explicitly.
53if(USE_PTHREADPOOL)
54  target_link_libraries(test_tensorexpr PRIVATE pthreadpool_interface)
55endif()
56if(USE_CUDA)
57  target_compile_definitions(test_tensorexpr PRIVATE USE_CUDA)
58  target_compile_definitions(tutorial_tensorexpr PRIVATE USE_CUDA)
59elseif(USE_ROCM)
60  target_link_libraries(test_tensorexpr PRIVATE
61    ${ROCM_HIPRTC_LIB}
62    ${PYTORCH_HIP_LIBRARIES}
63    ${TORCH_CUDA_LIBRARIES})
64  target_compile_definitions(test_tensorexpr PRIVATE USE_ROCM)
65
66  target_link_libraries(tutorial_tensorexpr PRIVATE
67    ${ROCM_HIPRTC_LIB}
68    ${PYTORCH_HIP_LIBRARIES}
69    ${TORCH_CUDA_LIBRARIES})
70  target_compile_definitions(tutorial_tensorexpr PRIVATE USE_ROCM)
71endif()
72
73if(INSTALL_TEST)
74  install(TARGETS test_tensorexpr DESTINATION bin)
75  install(TARGETS tutorial_tensorexpr DESTINATION bin)
76  # Install PDB files for MSVC builds
77  if(MSVC AND BUILD_SHARED_LIBS)
78    install(FILES $<TARGET_PDB_FILE:test_tensorexpr> DESTINATION bin OPTIONAL)
79    install(FILES $<TARGET_PDB_FILE:tutorial_tensorexpr> DESTINATION bin OPTIONAL)
80  endif()
81endif()
82