Repository: pytorch
Issue: cuda_utils.so: failed to map segment from shared object
Labels: triaged,oncall: pt2,module: inductor

### 🐛 Describe the bug

In docker with a tmpfs permission of `1777`, the model compiles well but when trying to execute the cached `cuda_utils.so` in `/tmp`, it errors with `failed to map segment from shared object`. Upon checking, it indeed does not have the execution bit while the dirs have.
```
drwxr-xr-x 2 root root    60 Mar 31 16:50 .
drwxr-xr-x 3 root root    60 Mar 31 16:50 ..
-rw-r--r-- 1 root root 27968 Mar 31 16:50 cuda_utils.so
```
The script is ran with root user so python should have every right to execute the binary.

### Error logs
```
  File "/usr/local/lib/python3.9/dist-packages/torch/nn/modules/module.py", line 1527, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/torch/nn/modules/module.py", line 1536, in _call_impl
    return forward_call(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/transformers/models/llava_next/modeling_llava_next.py", line 503, in forward
    image_features = self.vision_tower(reshaped_pixel_values, output_hidden_states=True)
  File "/usr/local/lib/python3.9/dist-packages/torch/nn/modules/module.py", line 1525, in _wrapped_call_impl
    return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/eval_frame.py", line 409, in _fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/torch/nn/modules/module.py", line 1536, in _call_impl
    return forward_call(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/convert_frame.py", line 939, in catch_errors
    return callback(frame, cache_entry, hooks, frame_state, skip=1)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/convert_frame.py", line 400, in _convert_frame_assert
    return _compile(
  File "/usr/lib/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/convert_frame.py", line 686, in _compile
    guarded_code = compile_inner(code, one_graph, hooks, transform)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/utils.py", line 265, in time_wrapper
    r = func(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/convert_frame.py", line 541, in compile_inner
    out_code = transform_code_object(code, transform)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/bytecode_transformation.py", line 1036, in transform_code_object
    transformations(instructions, code_options)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/convert_frame.py", line 165, in _fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/convert_frame.py", line 503, in transform
    tracer.run()
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/symbolic_convert.py", line 2116, in run
    super().run()
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/symbolic_convert.py", line 839, in run
    while self.step():
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/symbolic_convert.py", line 753, in step
    self.dispatch_table[inst.opcode](self, inst)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/symbolic_convert.py", line 2235, in RETURN_VALUE
    self.output.compile_subgraph(
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/output_graph.py", line 958, in compile_subgraph
    self.compile_and_call_fx_graph(tx, pass2.graph_output_vars(), root)
  File "/usr/lib/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/output_graph.py", line 1137, in compile_and_call_fx_graph
    compiled_fn = self.call_user_compiler(gm)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/utils.py", line 265, in time_wrapper
    r = func(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/output_graph.py", line 1210, in call_user_compiler
    raise BackendCompilerFailed(self.compiler_fn, e).with_traceback(
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/output_graph.py", line 1191, in call_user_compiler
    compiled_fn = compiler_fn(gm, self.example_inputs())
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/repro/after_dynamo.py", line 117, in debug_wrapper
    compiled_gm = compiler_fn(gm, example_inputs)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/repro/after_dynamo.py", line 117, in debug_wrapper
    compiled_gm = compiler_fn(gm, example_inputs)
  File "/usr/local/lib/python3.9/dist-packages/torch/__init__.py", line 1739, in __call__
    return compile_fx(model_, inputs_, config_patches=self.config)
  File "/usr/lib/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/compile_fx.py", line 1123, in compile_fx
    return compile_fx(
  File "/usr/lib/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/compile_fx.py", line 1351, in compile_fx
    return aot_autograd(
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/backends/common.py", line 58, in compiler_fn
    cg = aot_module_simplified(gm, example_inputs, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/torch/_functorch/aot_autograd.py", line 903, in aot_module_simplified
    compiled_fn = create_aot_dispatcher_function(
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/utils.py", line 265, in time_wrapper
    r = func(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/torch/_functorch/aot_autograd.py", line 628, in create_aot_dispatcher_function
    compiled_fn = compiler_fn(flat_fn, fake_flat_args, aot_config, fw_metadata=fw_metadata)
  File "/usr/local/lib/python3.9/dist-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 444, in aot_wrapper_dedupe
    return compiler_fn(flat_fn, leaf_flat_args, aot_config, fw_metadata=fw_metadata)
  File "/usr/local/lib/python3.9/dist-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 649, in aot_wrapper_synthetic_base
    return compiler_fn(flat_fn, flat_args, aot_config, fw_metadata=fw_metadata)
  File "/usr/local/lib/python3.9/dist-packages/torch/_functorch/_aot_autograd/jit_compile_runtime_wrappers.py", line 407, in aot_dispatch_autograd
    compiled_fw_func = aot_config.fw_compiler(fw_module, adjusted_flat_args)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/utils.py", line 265, in time_wrapper
    r = func(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/compile_fx.py", line 1278, in fw_compiler_base
    return inner_compile(
  File "/usr/lib/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/repro/after_aot.py", line 83, in debug_wrapper
    inner_compiled_fn = compiler_fn(gm, example_inputs)
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/debug.py", line 304, in inner
    return fn(*args, **kwargs)
  File "/usr/lib/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/usr/lib/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/utils.py", line 265, in time_wrapper
    r = func(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/compile_fx.py", line 449, in compile_fx_inner
    compiled_graph = FxGraphCache.load(
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/codecache.py", line 861, in load
    compiled_graph = compile_fx_fn(gm, example_inputs, **fx_kwargs)
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/compile_fx.py", line 732, in fx_codegen_and_compile
    compiled_fn = graph.compile_to_fn()
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/graph.py", line 1388, in compile_to_fn
    return self.compile_to_module().call
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/utils.py", line 265, in time_wrapper
    r = func(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/graph.py", line 1331, in compile_to_module
    self.codegen_with_cpp_wrapper() if self.cpp_wrapper else self.codegen()
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/graph.py", line 1287, in codegen
    self.scheduler.codegen()
  File "/usr/local/lib/python3.9/dist-packages/torch/_dynamo/utils.py", line 265, in time_wrapper
    r = func(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/scheduler.py", line 2429, in codegen
    self.get_backend(device).codegen_nodes(node.get_nodes())  # type: ignore[possibly-undefined]
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/codegen/cuda_combined_scheduling.py", line 63, in codegen_nodes
    return self._triton_scheduling.codegen_nodes(nodes)
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/codegen/triton.py", line 3307, in codegen_nodes
    return self.codegen_node_schedule(node_schedule, buf_accesses, numel, rnumel)
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/codegen/triton.py", line 3477, in codegen_node_schedule
    src_code = kernel.codegen_kernel()
  File "/usr/local/lib/python3.9/dist-packages/torch/_inductor/codegen/triton.py", line 2805, in codegen_kernel
    "backend_hash": torch.utils._triton.triton_hash_with_backend(),
  File "/usr/local/lib/python3.9/dist-packages/torch/utils/_triton.py", line 59, in triton_hash_with_backend
    backend = triton_backend()
  File "/usr/local/lib/python3.9/dist-packages/torch/utils/_triton.py", line 45, in triton_backend
    target = driver.get_current_target()
  File "/usr/local/lib/python3.9/dist-packages/triton/runtime/driver.py", line 22, in __getattr__
    self._initialize_obj()
  File "/usr/local/lib/python3.9/dist-packages/triton/runtime/driver.py", line 19, in _initialize_obj
    self._obj = self._init_fn()
  File "/usr/local/lib/python3.9/dist-packages/triton/runtime/driver.py", line 8, in _create_driver
    return actives[0]()
  File "/usr/local/lib/python3.9/dist-packages/triton/backends/cuda/driver.py", line 378, in __init__
    self.utils = CudaUtils()  # TODO: make static
  File "/usr/local/lib/python3.9/dist-packages/triton/backends/cuda/driver.py", line 47, in __init__
    mod = compile_module_from_src(Path(os.path.join(dirname, "driver.c")).read_text(), "cuda_utils")
  File "/usr/local/lib/python3.9/dist-packages/triton/backends/cuda/driver.py", line 29, in compile_module_from_src
    mod = importlib.util.module_from_spec(spec)
  File "<frozen importlib._bootstrap>", line 565, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1173, in create_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
ImportError: /tmp/triton/6e97c2a1f7a095255f6dd5de1807841d/cuda_utils.so: failed to map segment from shared object
```
### Minified repro

Any torch.compile triggers it. I used
```
torch._inductor.config.coordinate_descent_tuning = True
torch._inductor.config.triton.unique_kernel_names = True
torch._inductor.config.fx_graph_cache = True
```
if any of these matters.

Command i used to run the docker
`docker run --rm -it --mount type=tmpfs,destination=/tmp,tmpfs-size=5368709120,tmpfs-mode=1777 --memory-swap 0 --ulimit nproc=1024 --ulimit nofile=1024 --runtime=nvidia --gpus '"device=0"' --entrypoint bash image_name`

### Versions

PyTorch version: 2.4.0.dev20240326+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.35

Python version: 3.9.18 (main, Aug 25 2023, 13:20:14)  [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-5.19.0-051900rc6-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: Tesla V100-PCIE-16GB
Nvidia driver version: 545.23.08
cuDNN version: Probably one of the following:
/usr/local/lib/python3.9/dist-packages/nvidia/cudnn/lib/libcudnn.so.8
/usr/local/lib/python3.9/dist-packages/nvidia/cudnn/lib/libcudnn_cnn_infer.so.8
/usr/local/lib/python3.9/dist-packages/nvidia/cudnn/lib/libcudnn_ops_infer.so.8
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:                   46 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          40
On-line CPU(s) list:             0-39
Vendor ID:                       GenuineIntel
Model name:                      Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
CPU family:                      6
Model:                           85
Thread(s) per core:              1
Core(s) per socket:              20
Socket(s):                       2
Stepping:                        4
CPU max MHz:                     3700.0000
CPU min MHz:                     1000.0000
BogoMIPS:                        4800.00
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke md_clear flush_l1d arch_capabilities
L1d cache:                       1.3 MiB (40 instances)
L1i cache:                       1.3 MiB (40 instances)
L2 cache:                        40 MiB (40 instances)
L3 cache:                        55 MiB (2 instances)
NUMA node(s):                    2
NUMA node0 CPU(s):               0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38
NUMA node1 CPU(s):               1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39
Vulnerability Itlb multihit:     KVM: Mitigation: VMX unsupported
Vulnerability L1tf:              Mitigation; PTE Inversion
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT disabled
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Mmio stale data:   Mitigation; Clear CPU buffers; SMT disabled
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, IBPB conditional, IBRS_FW, RSB filling
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; SMT disabled

Versions of relevant libraries:
[pip3] flake8==7.0.0
[pip3] numpy==1.26.4
[pip3] pytest-flake8==1.1.1
[pip3] torch==2.4.0.dev20240326+cu121
[pip3] torchaudio==2.2.0.dev20240327+cu121
[pip3] torcheval==0.0.7
[pip3] torchvision==0.19.0.dev20240327+cu121
[pip3] triton-nightly==2.1.0.post20240108192258
[conda] Could not collect

cc @ezyang @msaroufim @bdhirsh @anijain2305 @chauhang @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @aakhundov @ColinPeppler @amjames @desertfire @zou3519