Repository: pytorch
Issue: Pytorch CXX11 ABI version
Labels: module: build,module: abi,triaged

### 🐛 Describe the bug

Hello, I met some problems recently. I have three third party shared libraries which is compiled with C++17. And I want to extend operators in these libraries to Pytorch. Therefore, I write a cpp file to test whether I linked thes libraries successfully.
The following is my example.cpp:
`


#include <torch/torch.h>
#include <iostream>
#include "conv.h"
using Tensor = torch::Tensor;
using IntArrayRef = torch::IntArrayRef;
int main() {
  std::cout << torch::cuda::is_available() << std::endl;
  std::cout << torch::cuda::cudnn_is_available() << std::endl;
  std::cout << torch::cuda::device_count() << std::endl;
  auto optionals =  at::TensorOptions(at::kCUDA).dtype(at::kFloat);
  Tensor input = torch::randint(1, 9,{2, 2, 5, 5}, optionals).to(c10::MemoryFormat::ChannelsLast);
  Tensor bias = torch::zeros({1}, optionals);
  Tensor weight = torch::randint(1, 9, {1, 2, 2, 2}, optionals).to(c10::MemoryFormat::ChannelsLast);
  c10::optional<Tensor> bias_opt{bias};
  IntArrayRef stride{1, 1};    // for senseconv must be dimension 2
  IntArrayRef padding{1, 1};   // for senseconv must be dimension 2
  IntArrayRef dilation{1, 1};  // for senseconv must be dimension 2 and {1, 1}
  int64_t groups = 1;
  Tensor ret = conv2d(input, weight, bias_opt, stride, padding, dilation, groups);
  std::cout << "Result1: " << std::endl;
  std::cout << ret << std::endl;
}
`
The conv2d is from "conv.h" which is from one of my third party libraries.
And the following is my cmakelists:

`

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(example)
set(CUDA_TOOLKIT_ROOT_DIR cuda11.7)
find_package(CUDA REQUIRED)
set(root_path /anaconda3/envs/torch2.0.1/lib/python3.10/site-packages/torch)
set(Torch_DIR ${root_path}/share/cmake/Torch)
find_package(Torch REQUIRED)
set(CUDNN_INCLUDE_DIRS ${CUDA_TOOLKIT_ROOT_DIR}/include)
include_directories(${CUDA_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIRS})
include_directories(${CMAKE_SOURCE_DIR}/include ${root_path}/include/torch/csrc/api/include/torch)
link_directories(${CUDA_TOOLKIT_ROOT_DIR}/lib64 ${CMAKE_SOURCE_DIR}/libs)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS} -DUSE_CUDNN")
add_executable(example example.cpp)
add_library(sensetorch SHARED IMPORTED)
set_property(TARGET sensetorch PROPERTY IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/libs/libtorch.so")
add_library(sensednn SHARED IMPORTED)
set_property(TARGET sensednn PROPERTY IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/libs/libdnn.so")
add_library(conv SHARED IMPORTED)
set_property(TARGET conv PROPERTY IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/libs/libconv.so")
target_link_libraries(example "${TORCH_LIBRARIES}")
target_link_libraries(example "${CUDA_LIBRARIES}")
target_link_libraries(example "${PythonInterp_LIBRARIES}")
target_link_libraries(example conv sensednn sensetorch)
`

everything goes fine when compiling. However, when I run the example, it occurs errors. The error is :
`
free(): invalid pointer
Aborted
`

Therefore, I consider that there is an incompatability between pytorch and my third party libraries. However, when I modify the torch path(using libtorch C++ with CXX11 ABI version) in cmakelists, everythins is fine. The libtorch version is the following.

<img width="671" alt="捕获" src="https://github.com/pytorch/pytorch/assets/45058324/defa24a5-ece8-40b5-b6ea-51baf6120cd2">

I found that my pytorch's CXX11ABI version is pre-CXX11 ABI version. So, how can I solve this as I want to use the libtorch in pytorch not the C++ libtorch. Because I want to extend them into pytorch in the future.

### Versions

Collecting environment information...
PyTorch version: 1.12.1
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.5 LTS (x86_64)
GCC version: (GCC) 10.2.0
Clang version: Could not collect
CMake version: version 3.26.3
Libc version: glibc-2.27

Python version: 3.10.9 (main, Mar  1 2023, 18:23:06) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-3.10.0-1160.el7.x86_64-x86_64-with-glibc2.27
Is CUDA available: False
CUDA runtime version: 11.7.99
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: GPU 0: NVIDIA A100-SXM4-80GB
Nvidia driver version: 470.103.01
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.0.5
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
Byte Order:          Little Endian
CPU(s):              128
On-line CPU(s) list: 0-127
Thread(s) per core:  2
Core(s) per socket:  32
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               106
Model name:          Intel(R) Xeon(R) Platinum 8369B CPU @ 2.90GHz
Stepping:            6
CPU MHz:             3499.859
CPU max MHz:         3500.0000
CPU min MHz:         800.0000
BogoMIPS:            5800.00
Virtualization:      VT-x
L1d cache:           48K
L1i cache:           32K
L2 cache:            1280K
L3 cache:            49152K
NUMA node0 CPU(s):   0-31,64-95
NUMA node1 CPU(s):   32-63,96-127
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 aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx 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 epb cat_l3 invpcid_single intel_pt ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 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 avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq md_clear pconfig spec_ctrl intel_stibp flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] flake8==6.0.0
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.23.5
[pip3] numpydoc==1.5.0
[pip3] torch==1.12.1
[conda] blas                      1.0                         mkl  
[conda] mkl                       2021.4.0           h06a4308_640  
[conda] mkl-service               2.4.0           py310h7f8727e_0  
[conda] mkl_fft                   1.3.1           py310hd6ae3a3_0  
[conda] mkl_random                1.2.2           py310h00e6091_0  
[conda] numpy                     1.23.5          py310hd5efca6_0  
[conda] numpy-base                1.23.5          py310h8e6c178_0  
[conda] numpydoc                  1.5.0           py310h06a4308_0  
[conda] pytorch                   1.12.1          cpu_py310hb1f1ab4_1  

cc @malfet @seemethere