xref: /aosp_15_r20/external/pytorch/cmake/Modules/FindARM.cmake (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1# Check if the processor is an ARM and if Neon instruction are available on the machine where
2# the project is compiled.
3
4IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
5   EXECUTE_PROCESS(COMMAND cat /proc/cpuinfo OUTPUT_VARIABLE CPUINFO)
6
7   #neon instruction can be found on the majority part of modern ARM processor
8   STRING(REGEX REPLACE "^.*(neon).*$" "\\1" NEON_THERE "${CPUINFO}")
9   STRING(COMPARE EQUAL "neon" "${NEON_THERE}" NEON_TRUE)
10   IF (NEON_TRUE)
11      set(NEON_FOUND true CACHE BOOL "NEON available on host")
12   ELSE (NEON_TRUE)
13      set(NEON_FOUND false CACHE BOOL "NEON available on host")
14   ENDIF (NEON_TRUE)
15
16   # on ARMv8, neon is inherit and instead listed as 'asimd' in /proc/cpuinfo
17   STRING(REGEX REPLACE "^.*(asimd).*$" "\\1" ASIMD_THERE "${CPUINFO}")
18   STRING(COMPARE EQUAL "asimd" "${ASIMD_THERE}" ASIMD_TRUE)
19   IF (ASIMD_TRUE)
20      set(ASIMD_FOUND true CACHE BOOL "ASIMD/NEON available on host")
21   ELSE (ASIMD_TRUE)
22      set(ASIMD_FOUND false CACHE BOOL "ASIMD/NEON available on host")
23   ENDIF (ASIMD_TRUE)
24
25   #Find the processor type (for now OMAP3 or OMAP4)
26   STRING(REGEX REPLACE "^.*(OMAP3).*$" "\\1" OMAP3_THERE "${CPUINFO}")
27   STRING(COMPARE EQUAL "OMAP3" "${OMAP3_THERE}" OMAP3_TRUE)
28   IF (OMAP3_TRUE)
29      set(CORTEXA8_FOUND true CACHE BOOL "OMAP3 available on host")
30   ELSE (OMAP3_TRUE)
31      set(CORTEXA8_FOUND false CACHE BOOL "OMAP3 available on host")
32   ENDIF (OMAP3_TRUE)
33
34   #Find the processor type (for now OMAP3 or OMAP4)
35   STRING(REGEX REPLACE "^.*(OMAP4).*$" "\\1" OMAP4_THERE "${CPUINFO}")
36   STRING(COMPARE EQUAL "OMAP4" "${OMAP4_THERE}" OMAP4_TRUE)
37   IF (OMAP4_TRUE)
38      set(CORTEXA9_FOUND true CACHE BOOL "OMAP4 available on host")
39   ELSE (OMAP4_TRUE)
40      set(CORTEXA9_FOUND false CACHE BOOL "OMAP4 available on host")
41   ENDIF (OMAP4_TRUE)
42
43ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Darwin")
44   IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64" AND NOT CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
45      set(NEON_FOUND true CACHE BOOL "NEON available on ARM64")
46   ENDIF()
47   EXECUTE_PROCESS(COMMAND /usr/sbin/sysctl -n machdep.cpu.features OUTPUT_VARIABLE
48      CPUINFO)
49
50   IF(NOT CPUINFO STREQUAL "")
51       #neon instruction can be found on the majority part of modern ARM processor
52       STRING(REGEX REPLACE "^.*(neon).*$" "\\1" NEON_THERE "${CPUINFO}")
53       STRING(COMPARE EQUAL "neon" "${NEON_THERE}" NEON_TRUE)
54       IF (NEON_TRUE)
55          set(NEON_FOUND true CACHE BOOL "NEON available on host")
56       ELSE (NEON_TRUE)
57          set(NEON_FOUND false CACHE BOOL "NEON available on host")
58       ENDIF (NEON_TRUE)
59   ENDIF()
60
61ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Windows")
62   # TODO
63   set(CORTEXA8_FOUND   false CACHE BOOL "OMAP3 not available on host")
64   set(CORTEXA9_FOUND   false CACHE BOOL "OMAP4 not available on host")
65   set(NEON_FOUND   false CACHE BOOL "NEON not available on host")
66ELSE(CMAKE_SYSTEM_NAME MATCHES "Linux")
67   set(CORTEXA8_FOUND   false CACHE BOOL "OMAP3 not available on host")
68   set(CORTEXA9_FOUND   false CACHE BOOL "OMAP4 not available on host")
69   set(NEON_FOUND   false CACHE BOOL "NEON not available on host")
70ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
71
72if(NOT NEON_FOUND)
73      MESSAGE(STATUS "Could not find hardware support for NEON on this machine.")
74endif(NOT NEON_FOUND)
75if(NOT CORTEXA8_FOUND)
76      MESSAGE(STATUS "No OMAP3 processor on this machine.")
77endif(NOT CORTEXA8_FOUND)
78if(NOT CORTEXA9_FOUND)
79      MESSAGE(STATUS "No OMAP4 processor on this machine.")
80endif(NOT CORTEXA9_FOUND)
81mark_as_advanced(NEON_FOUND)
82