Skip to content

Commit ba7a2f6

Browse files
cccclaifacebook-github-bot
authored andcommitted
Add debug helper function to check target property (pytorch#52093)
Summary: Pull Request resolved: pytorch#52093 # Summary The previous debug if statement only prints the file list, but it's not clear whether the target includes the file list correctly. This function can examine the target so it's more accurate. This pr includes changes: 1. Add a file `DebugHelper.cmake` with `print_target_properties` function. 2. Replace the debug if statement `if(FALSE)` by adding magical variable `PRINT_CMAKE_DEBUG_INFO` and applying the variable accordingly. Note: previous debug if statement output example: ``` -- CPU sources: -- /Users/chenlai/pytorch/aten/src/ATen/BatchedFallback.cpp -- /Users/chenlai/pytorch/aten/src/ATen/BatchedTensorImpl.cpp -- /Users/chenlai/pytorch/aten/src/ATen/BatchingRegistrations.cpp -- /Users/chenlai/pytorch/aten/src/ATen/CPUGeneratorImpl.cpp -- /Users/chenlai/pytorch/aten/src/ATen/Context.cpp -- /Users/chenlai/pytorch/aten/src/ATen/DLConvertor.cpp -- /Users/chenlai/pytorch/aten/src/ATen/DynamicLibrary.cpp -- /Users/chenlai/pytorch/aten/src/ATen/ExpandUtils.cpp -- /Users/chenlai/pytorch/aten/src/ATen/LegacyTHFunctionsCPU.cpp -- /Users/chenlai/pytorch/aten/src/ATen/MemoryOverlap.cpp ... -- GPU sources: -- CPU include: -- /Users/chenlai/pytorch/build_android/caffe2/aten/src/TH -- /Users/chenlai/pytorch/aten/src/TH -- /Users/chenlai/pytorch/aten/src -- /Users/chenlai/pytorch/build_android/caffe2/aten/src ... -- GPU include: -- /Users/chenlai/pytorch/build_android/caffe2/aten/src/TH -- /Users/chenlai/pytorch/aten/src/TH -- /Users/chenlai/pytorch/build_android/caffe2/aten/src/TH -- /Users/chenlai/pytorch/aten/src/TH ``` # Test plan Set `PRINT_CMAKE_DEBUG_INFO` to true by adding `DPRINT_CMAKE_DEBUG_INFO` in `./scripts/build_pytorch_android.sh`, run `./scripts/build_pytorch_android.sh x86` `print_target_properties(torch)` shows ``` torch ANDROID_ARCH = x86 torch ANDROID_STL_TYPE = c++_static torch ARCHIVE_OUTPUT_DIRECTORY = /Users/chenlai/pytorch/build_android_x86/lib torch AUTOGEN_ORIGIN_DEPENDS = ON torch AUTOMOC_COMPILER_PREDEFINES = ON torch AUTOMOC_MACRO_NAMES = Q_OBJECT;Q_GADGET;Q_NAMESPACE;Q_NAMESPACE_EXPORT torch AUTOMOC_PATH_PREFIX = OFF torch BINARY_DIR = /Users/chenlai/pytorch/build_android_x86/caffe2 torch BINARY_DIR = /Users/chenlai/pytorch/build_android_x86/caffe2 torch BUILD_WITH_INSTALL_RPATH = FALSE torch CXX_STANDARD = 14 torch C_STANDARD = 11 torch IMPORTED = FALSE torch IMPORTED_GLOBAL = FALSE torch INCLUDE_DIRECTORIES = /Users/chenlai/pytorch/build_android_x86/aten/src;/Users/chenlai/pytorch/aten/src;/Users/chenlai/pytorch/build_android_x86;/Users/chenlai/pytorch;/Users/chenlai/pytorch/third_party/XNNPACK/include;/Users/chenlai/Library/Android/sdk/ndk/21.3.6528147/sources/third_party/vulkan/src/common;/Users/chenlai/pytorch/cmake/../third_party/eigen;/Users/chenlai/pytorch/cmake/../third_party/pybind11/include torch INCLUDE_DIRECTORIES = /Users/chenlai/pytorch/build_android_x86/aten/src;/Users/chenlai/pytorch/aten/src;/Users/chenlai/pytorch/build_android_x86;/Users/chenlai/pytorch;/Users/chenlai/pytorch/third_party/XNNPACK/include;/Users/chenlai/Library/Android/sdk/ndk/21.3.6528147/sources/third_party/vulkan/src/common;/Users/chenlai/pytorch/cmake/../third_party/eigen;/Users/chenlai/pytorch/cmake/../third_party/pybind11/include torch INCLUDE_DIRECTORIES = /Users/chenlai/pytorch/build_android_x86/aten/src;/Users/chenlai/pytorch/aten/src;/Users/chenlai/pytorch/build_android_x86;/Users/chenlai/pytorch;/Users/chenlai/pytorch/third_party/XNNPACK/include;/Users/chenlai/Library/Android/sdk/ndk/21.3.6528147/sources/third_party/vulkan/src/common;/Users/chenlai/pytorch/cmake/../third_party/eigen;/Users/chenlai/pytorch/cmake/../third_party/pybind11/include torch INSTALL_RPATH = $ORIGIN torch INSTALL_RPATH_USE_LINK_PATH = TRUE torch INTERFACE_LINK_LIBRARIES = torch_cpu_library torch ISPC_HEADER_SUFFIX = _ispc.h torch LIBRARY_OUTPUT_DIRECTORY = /Users/chenlai/pytorch/build_android_x86/lib torch LINK_LIBRARIES = torch_cpu_library torch NAME = torch torch PCH_INSTANTIATE_TEMPLATES = ON torch PCH_WARN_INVALID = ON torch POSITION_INDEPENDENT_CODE = TRUE torch RUNTIME_OUTPUT_DIRECTORY = /Users/chenlai/pytorch/build_android_x86/bin torch SKIP_BUILD_RPATH = FALSE torch SOURCES = /Users/chenlai/pytorch/build_android_x86/empty.cpp torch SOURCE_DIR = /Users/chenlai/pytorch/caffe2 torch SOURCE_DIR = /Users/chenlai/pytorch/caffe2 torch TYPE = STATIC_LIBRARY torch TYPE = STATIC_LIBRARY torch UNITY_BUILD_BATCH_SIZE = 8 torch UNITY_BUILD_MODE = BATCH ``` Test Plan: Imported from OSS Reviewed By: walterddr Differential Revision: D26377725 Pulled By: cccclai fbshipit-source-id: dbe21ad533759f33711a0ce5328205bbcd5cf0f3
1 parent 22b1217 commit ba7a2f6

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

caffe2/CMakeLists.txt

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ if(MSVC)
1111
include(../cmake/public/utils.cmake)
1212
endif()
1313

14+
# Debug messages - if you want to get a list of source files and examine
15+
# target information, enable the following by -DPRINT_CMAKE_DEBUG_INFO=ON.
16+
set(PRINT_CMAKE_DEBUG_INFO FALSE CACHE BOOL "print cmake debug information")
17+
if(PRINT_CMAKE_DEBUG_INFO)
18+
include(../cmake/DebugHelper.cmake)
19+
endif()
20+
1421
# ATen parallelism settings
1522
# OMP - OpenMP for intra-op, native thread pool for inter-op parallelism
1623
# NATIVE - using native thread pool for intra- and inter-op parallelism
@@ -186,9 +193,7 @@ if(BUILD_SPLIT_CUDA)
186193
endforeach()
187194
endif()
188195

189-
# Debug messages - if you want to get a list of source files, enable the
190-
# following.
191-
if(FALSE)
196+
if(PRINT_CMAKE_DEBUG_INFO)
192197
message(STATUS "CPU sources: ")
193198
foreach(tmp ${Caffe2_CPU_SRCS})
194199
message(STATUS " " ${tmp})
@@ -1265,6 +1270,11 @@ elseif(USE_ROCM)
12651270
target_link_libraries(torch PUBLIC torch_hip_library)
12661271
endif()
12671272

1273+
if(PRINT_CMAKE_DEBUG_INFO)
1274+
print_target_properties(torch)
1275+
print_target_properties(torch_cpu)
1276+
endif()
1277+
12681278
# Install PDB files for MSVC builds
12691279
if(MSVC AND BUILD_SHARED_LIBS)
12701280
install(FILES $<TARGET_PDB_FILE:torch_cpu> DESTINATION "${TORCH_INSTALL_LIB_DIR}" OPTIONAL)

cmake/DebugHelper.cmake

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function(print_target_properties tgt)
2+
# Get all propreties that cmake supports
3+
execute_process(COMMAND cmake --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST)
4+
5+
# Convert command output into a CMake list
6+
STRING(REGEX REPLACE ";" "\\\\;" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}")
7+
STRING(REGEX REPLACE "\n" ";" CMAKE_PROPERTY_LIST "${CMAKE_PROPERTY_LIST}")
8+
if(NOT TARGET ${tgt})
9+
message("There is no target named '${tgt}'")
10+
return()
11+
endif()
12+
13+
foreach(prop ${CMAKE_PROPERTY_LIST})
14+
string(REPLACE "<CONFIG>" "${CMAKE_BUILD_TYPE}" prop ${prop})
15+
# Fix https://stackoverflow.com/questions/32197663/how-can-i-remove-the-the-location-property-may-not-be-read-from-target-error-i
16+
if(prop STREQUAL "LOCATION" OR prop MATCHES "^LOCATION_" OR prop MATCHES "_LOCATION$")
17+
continue()
18+
endif()
19+
# message ("Checking ${prop}")
20+
get_property(propval TARGET ${tgt} PROPERTY ${prop} SET)
21+
if(propval)
22+
get_target_property(propval ${tgt} ${prop})
23+
message("${tgt} ${prop} = ${propval}")
24+
endif()
25+
endforeach(prop)
26+
endfunction(print_target_properties)

0 commit comments

Comments
 (0)