Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatc should be built for the host rather than the target when cross-compiling #7260

Open
fiberflow opened this issue Dec 10, 2024 · 0 comments

Comments

@fiberflow
Copy link

fiberflow commented Dec 10, 2024

🐛 Describe the bug

add_subdirectory(third-party/flatbuffers)

It could be fixed with something like this.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 46fec4cf0..62dfa6e62 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -475,12 +475,24 @@ if(EXECUTORCH_BUILD_FLATC)
       OFF
       CACHE BOOL ""
   )
-  add_subdirectory(third-party/flatbuffers)
 
-  # exir lets users set the alignment of tensor data embedded in the flatbuffer,
-  # and some users need an alignment larger than the default, which is typically
-  # 32.
-  target_compile_definitions(flatc PRIVATE FLATBUFFERS_MAX_ALIGNMENT=1024)
+  if(CMAKE_CROSSCOMPILING)
+    set(FLATC_EXECUTABLE  ${CMAKE_BINARY_DIR}/_host_build_flatbuffers/flatc)
+    execute_process(
+      COMMAND
+        ${CMAKE_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR}/third-party/flatbuffers -DCMAKE_C_FLAGS=-DFLATBUFFERS_MAX_ALIGNMENT=1024 -B${CMAKE_BINARY_DIR}/_host_build_flatbuffers
+    )
+    execute_process(
+      COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/_host_build_flatbuffers -j
+    )
+  else()
+    add_subdirectory(third-party/flatbuffers)
+
+    # exir lets users set the alignment of tensor data embedded in the flatbuffer,
+    # and some users need an alignment larger than the default, which is typically
+    # 32.
+    target_compile_definitions(flatc PRIVATE FLATBUFFERS_MAX_ALIGNMENT=1024)
+  endif()
 endif()
 if(NOT FLATC_EXECUTABLE)
   message(

Versions

Collecting environment information...
PyTorch version: 2.6.0.dev20241112+cpu
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.1 LTS (x86_64)
GCC version: (Ubuntu 13.2.0-23ubuntu4) 13.2.0
Clang version: Could not collect
CMake version: version 3.31.1
Libc version: glibc-2.39

Python version: 3.12.3 (main, Nov  6 2024, 18:32:19) [GCC 13.2.0] (64-bit runtime)
Python platform: Linux-6.8.0-48-generic-x86_64-with-glibc2.39
Is CUDA available: False
CUDA runtime version: 11.5.119
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.5.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Address sizes:                        43 bits physical, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               12
On-line CPU(s) list:                  0-11
Vendor ID:                            AuthenticAMD
Model name:                           AMD Ryzen 5 1600 Six-Core Processor
CPU family:                           23
Model:                                1
Thread(s) per core:                   2
Core(s) per socket:                   6
Socket(s):                            1
Stepping:                             1
Frequency boost:                      enabled
CPU(s) scaling MHz:                   51%
CPU max MHz:                          3200.0000
CPU min MHz:                          1550.0000
BogoMIPS:                             6388.26
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb hw_pstate ssbd vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 clzero irperf xsaveerptr arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca sev
L1d cache:                            192 KiB (6 instances)
L1i cache:                            384 KiB (6 instances)
L2 cache:                             3 MiB (6 instances)
L3 cache:                             16 MiB (2 instances)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-11
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Mitigation; untrained return thunk; SMT vulnerable
Vulnerability Spec rstack overflow:   Vulnerable: Safe RET, no microcode
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Retpolines; STIBP disabled; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] numpy==2.2.0
[pip3] torch==2.6.0.dev20241112+cpu
[pip3] torchaudio==2.5.0.dev20241112+cpu
[pip3] torchsr==1.0.4
[pip3] torchvision==0.20.0.dev20241112+cpu
[conda] numpy                     1.21.6                   pypi_0    pypi
[conda] torch                     1.12.1                   pypi_0    pypi
[conda] torchvision               0.9.0                    pypi_0    pypi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant