xref: /aosp_15_r20/external/pytorch/test/cpp/api/CMakeLists.txt (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1set(TORCH_API_TEST_DIR "${TORCH_ROOT}/test/cpp/api")
2set(TORCH_API_TEST_SOURCES
3  ${TORCH_ROOT}/test/cpp/common/main.cpp
4  ${TORCH_API_TEST_DIR}/autograd.cpp
5  ${TORCH_API_TEST_DIR}/any.cpp
6  ${TORCH_API_TEST_DIR}/dataloader.cpp
7  ${TORCH_API_TEST_DIR}/enum.cpp
8  ${TORCH_API_TEST_DIR}/expanding-array.cpp
9  ${TORCH_API_TEST_DIR}/fft.cpp
10  ${TORCH_API_TEST_DIR}/functional.cpp
11  ${TORCH_API_TEST_DIR}/init.cpp
12  ${TORCH_API_TEST_DIR}/integration.cpp
13  ${TORCH_API_TEST_DIR}/ivalue.cpp
14  ${TORCH_API_TEST_DIR}/jit.cpp
15  ${TORCH_API_TEST_DIR}/memory.cpp
16  ${TORCH_API_TEST_DIR}/meta_tensor.cpp
17  ${TORCH_API_TEST_DIR}/misc.cpp
18  ${TORCH_API_TEST_DIR}/module.cpp
19  ${TORCH_API_TEST_DIR}/moduledict.cpp
20  ${TORCH_API_TEST_DIR}/modulelist.cpp
21  ${TORCH_API_TEST_DIR}/modules.cpp
22  ${TORCH_API_TEST_DIR}/nested.cpp
23  ${TORCH_API_TEST_DIR}/parameterdict.cpp
24  ${TORCH_API_TEST_DIR}/parameterlist.cpp
25  ${TORCH_API_TEST_DIR}/namespace.cpp
26  ${TORCH_API_TEST_DIR}/nn_utils.cpp
27  ${TORCH_API_TEST_DIR}/optim.cpp
28  ${TORCH_API_TEST_DIR}/ordered_dict.cpp
29  ${TORCH_API_TEST_DIR}/rnn.cpp
30  ${TORCH_API_TEST_DIR}/sequential.cpp
31  ${TORCH_API_TEST_DIR}/transformer.cpp
32  ${TORCH_API_TEST_DIR}/serialize.cpp
33  ${TORCH_API_TEST_DIR}/special.cpp
34  ${TORCH_API_TEST_DIR}/static.cpp
35  ${TORCH_API_TEST_DIR}/support.cpp
36  ${TORCH_API_TEST_DIR}/tensor_cuda.cpp
37  ${TORCH_API_TEST_DIR}/tensor_indexing.cpp
38  ${TORCH_API_TEST_DIR}/tensor_options_cuda.cpp
39  ${TORCH_API_TEST_DIR}/tensor_options.cpp
40  ${TORCH_API_TEST_DIR}/tensor.cpp
41  ${TORCH_API_TEST_DIR}/torch_include.cpp
42  ${TORCH_API_TEST_DIR}/inference_mode.cpp
43  ${TORCH_API_TEST_DIR}/grad_mode.cpp
44  ${TORCH_API_TEST_DIR}/operations.cpp
45  ${TORCH_API_TEST_DIR}/nested_int.cpp
46)
47if(USE_CUDA OR USE_ROCM)
48  list(APPEND TORCH_API_TEST_SOURCES ${TORCH_API_TEST_DIR}/parallel.cpp)
49endif()
50
51add_executable(test_api ${TORCH_API_TEST_SOURCES})
52target_include_directories(test_api PRIVATE ${ATen_CPU_INCLUDE})
53target_link_libraries(test_api PRIVATE torch gtest)
54
55if(USE_CUDA)
56  target_compile_definitions(test_api PRIVATE "USE_CUDA")
57endif()
58
59if(NOT MSVC)
60  # Clang has an unfixed bug leading to spurious missing braces
61  # warnings, see https://bugs.llvm.org/show_bug.cgi?id=21629
62  target_compile_options_if_supported(test_api "-Wno-missing-braces")
63  # Considered to be flaky.  See the discussion at
64  # https://github.com/pytorch/pytorch/pull/9608
65  target_compile_options_if_supported(test_api "-Wno-maybe-uninitialized")
66  # gcc gives nonsensical warnings about variadic.h
67  target_compile_options_if_supported(test_api "-Wno-unused-but-set-parameter")
68endif()
69
70if(INSTALL_TEST)
71  install(TARGETS test_api DESTINATION bin)
72  # Install PDB files for MSVC builds
73  if(MSVC AND BUILD_SHARED_LIBS)
74    install(FILES $<TARGET_PDB_FILE:test_api> DESTINATION bin OPTIONAL)
75  endif()
76endif()
77
78add_executable(parallel_benchmark ${TORCH_API_TEST_DIR}/parallel_benchmark.cpp)
79target_include_directories(parallel_benchmark PRIVATE ${ATen_CPU_INCLUDE})
80target_link_libraries(parallel_benchmark PRIVATE torch)
81