Repository navigation
关于使用sycl进行异构编程时输出c++运行时差异导致的异常不匹配问题。 #838
Copy link
Copy link
Closed
Description
问题描述:
sycl lane 的 libtensorvia.so 里同时进了 libsycl 的 libstdc++ 符号和 llvm 主体的 libc++ 符号,测试二进制(libc++)的 catch (const std::exception&) 匹配不到 .so 内实际抛出的那个 std::exception 实体(两套 STL 的 typeinfo 不是一个东西)。
所以在 src/backend/cpu/ops/*.cpp 里找抛点能找到 throw std::runtime_error,代码本身没毛病——坏的是链接进同一个 .so 的两个 C++ 运行时。
复现:
git clone https://github.com/Aimol-l/Tensorvia.git
sycl + llvm 运行测试程序异常:mcpp test --features sycl --accel sycl
Running main() from /home/aimol/.mcpp/xpkgs/compat-x-gtest/1.17.0/googletest-1.17.0/googletest/src/gtest_main.cc
[==========] Running 23 tests from 11 test suites.
[----------] Global test environment set-up.
[----------] 1 test from Tensorvia
[ RUN ] Tensorvia.BasicArithmetic
[ OK ] Tensorvia.BasicArithmetic (0 ms)
[----------] 1 test from Tensorvia (0 ms total)
[----------] 6 tests from View
[ RUN ] View.SliceReadAndInPlaceArithmetic
[ OK ] View.SliceReadAndInPlaceArithmetic (0 ms)
[ RUN ] View.TransposedView
[ OK ] View.TransposedView (0 ms)
[ RUN ] View.CloneAndTypecast
[ OK ] View.CloneAndTypecast (0 ms)
[ RUN ] View.Permute3D
[ OK ] View.Permute3D (0 ms)
[ RUN ] View.InPlaceRejectsNonContiguous
/home/aimol/Documents/C++/Workspace/MCPP/Tensorvia/tests/test.cpp:160: Failure
Expected: ops::Add(xt, 1.0f) throws an exception of type std::exception.
Actual: it throws a different type.
/home/aimol/Documents/C++/Workspace/MCPP/Tensorvia/tests/test.cpp:161: Failure
Expected: ops::Relu(xt) throws an exception of type std::exception.
Actual: it throws a different type.
/home/aimol/Documents/C++/Workspace/MCPP/Tensorvia/tests/test.cpp:162: Failure
Expected: ops::Fill(xt, 5.0f) throws an exception of type std::exception.
Actual: it throws a different type.
/home/aimol/Documents/C++/Workspace/MCPP/Tensorvia/tests/test.cpp:163: Failure
Expected: ops::Transpose(xt) throws an exception of type std::exception.
Actual: it throws a different type.
[ FAILED ] View.InPlaceRejectsNonContiguous (0 ms)
[ RUN ] View.DstBinaryOnTransposedView
[ OK ] View.DstBinaryOnTransposedView (0 ms)
[----------] 6 tests from View (0 ms total)
[----------] 1 test from Tensor
[ RUN ] Tensor.ReferenceSemantics
[ OK ] Tensor.ReferenceSemantics (0 ms)
[----------] 1 test from Tensor (0 ms total)
[----------] 1 test from DType
[ RUN ] DType.MixedPromotion
[ OK ] DType.MixedPromotion (0 ms)
[----------] 1 test from DType (0 ms total)
[----------] 1 test from MatMul
[ RUN ] MatMul.MatchesNaiveGemm
[ OK ] MatMul.MatchesNaiveGemm (39 ms)
[----------] 1 test from MatMul (39 ms total)
[----------] 3 tests from Reduce
[ RUN ] Reduce.ArgmaxArgminIndexType
[ OK ] Reduce.ArgmaxArgminIndexType (0 ms)
[ RUN ] Reduce.OneDimAxis
[ OK ] Reduce.OneDimAxis (0 ms)
[ RUN ] Reduce.ArgmaxTieBreak
[ OK ] Reduce.ArgmaxTieBreak (0 ms)
[----------] 3 tests from Reduce (0 ms total)
[----------] 3 tests from Broadcast
[ RUN ] Broadcast.Arithmetic
/home/aimol/Documents/C++/Workspace/MCPP/Tensorvia/tests/test.cpp:389: Failure
Expected: (brow + bad) throws an exception of type std::exception.
Actual: it throws a different type.
/home/aimol/Documents/C++/Workspace/MCPP/Tensorvia/tests/test.cpp:392: Failure
Expected: ops::Add(brow, bmat, bdst2) throws an exception of type std::exception.
Actual: it throws a different type.
[ FAILED ] Broadcast.Arithmetic (0 ms)
[ RUN ] Broadcast.Comparison
[ OK ] Broadcast.Comparison (0 ms)
[ RUN ] Broadcast.ScalarComparison
[ OK ] Broadcast.ScalarComparison (0 ms)
[----------] 3 tests from Broadcast (0 ms total)
[----------] 1 test from Metadata
[ RUN ] Metadata.DimArray
/home/aimol/Documents/C++/Workspace/MCPP/Tensorvia/tests/test.cpp:489: Failure
Expected: (Tensor({1, 1, 1, 1, 1, 1, 1, 1, 1}, DataType::FLOAT32)) throws an exception of type std::exception.
Actual: it throws a different type.
[ FAILED ] Metadata.DimArray (0 ms)
[----------] 1 test from Metadata (0 ms total)
[----------] 4 tests from Numeric
[ RUN ] Numeric.Transcendentals
[ OK ] Numeric.Transcendentals (0 ms)
[ RUN ] Numeric.IntegerSoftmax
[ OK ] Numeric.IntegerSoftmax (0 ms)
[ RUN ] Numeric.ReductionsAndSpecialFunctions
[ OK ] Numeric.ReductionsAndSpecialFunctions (0 ms)
[ RUN ] Numeric.NormsAndLosses
[ OK ] Numeric.NormsAndLosses (0 ms)
[----------] 4 tests from Numeric (0 ms total)
[----------] 1 test from Create
[ RUN ] Create.ArangeLinspaceEye
/home/aimol/Documents/C++/Workspace/MCPP/Tensorvia/tests/test.cpp:588: Failure
Expected: ops::Arange(0, 5, 0.0f) throws an exception of type std::exception.
Actual: it throws a different type.
/home/aimol/Documents/C++/Workspace/MCPP/Tensorvia/tests/test.cpp:589: Failure
Expected: ops::Arange(0, 5, -1.0f) throws an exception of type std::exception.
Actual: it throws a different type.
[ FAILED ] Create.ArangeLinspaceEye (0 ms)
[----------] 1 test from Create (0 ms total)
[----------] 1 test from Indexing
[ RUN ] Indexing.WhereIndexSelectGather
/home/aimol/Documents/C++/Workspace/MCPP/Tensorvia/tests/test.cpp:714: Failure
Expected: ops::IndexSelect(emb, 0, gi) throws an exception of type std::exception.
Actual: it throws a different type.
/home/aimol/Documents/C++/Workspace/MCPP/Tensorvia/tests/test.cpp:717: Failure
Expected: ops::IndexSelect(emb, 0, idx_bad) throws an exception of type std::exception.
Actual: it throws a different type.
[ FAILED ] Indexing.WhereIndexSelectGather (0 ms)
[----------] 1 test from Indexing (0 ms total)
[----------] Global test environment tear-down
[==========] 23 tests from 11 test suites ran. (41 ms total)
[ PASSED ] 18 tests.
[ FAILED ] 5 tests, listed below:
[ FAILED ] View.InPlaceRejectsNonContiguous
[ FAILED ] Broadcast.Arithmetic
[ FAILED ] Metadata.DimArray
[ FAILED ] Create.ArangeLinspaceEye
[ FAILED ] Indexing.WhereIndexSelectGather
5 FAILED TESTS
bench ... ok (2.57s)
add f32 16M 7.141 ms 28.19 GB/s
mul f32 16M 7.171 ms 28.07 GB/s
add-scalar f32 16M 3.005 ms 44.66 GB/s
exp f32 4M 1.350 ms 24.86 GB/s
sum f32 16M 8.508 ms 7.89 GB/s
sum-axis1 4096x4096 2.435 ms 27.57 GB/s
transpose2d 1024x1024 0.743 ms 11.29 GB/s
transpose3d 64^3 0.042 ms 50.13 GB/s
gather permute 128x64x64 1.552 ms 2.70 GB/s
matmul f32 256 0.339 ms 99.11 GFLOPS
matmul f32 512 2.644 ms 101.54 GFLOPS
arange f32 16M 16.450 ms 4.08 GB/s
where f32 16M 55.580 ms 4.83 GB/s
where-scalar f32 16M 7.966 ms 25.27 GB/s
index_select 4096x64 0.024 ms 86.76 GB/s
gather 1024x1024 2.327 ms 5.41 GB/s
layer_norm f32 8192x4096 20.891 ms 25.70 GB/s
rms_norm f32 8192x4096 16.918 ms 23.80 GB/s
randn f32 16M 70.385 ms 0.95 GB/s
mse_loss f32 16M 21.097 ms 6.36 GB/s
nll_loss f32 65536x1024 0.093 ms 2.81 GB/s
cross_entropy f32 8192x256 1.708 ms 19.65 GB/s
error: test result: FAILED. 1 passed; 1 failed; finished in 49.74s (build 44.50s + run 2.57s)
failures:
test
sycl + gcc 运行测试程序正常:mcpp test --toolchain gcc@16.1.0 --features sycl --accel sycl
Running main() from /home/aimol/.mcpp/xpkgs/compat-x-gtest/1.17.0/googletest-1.17.0/googletest/src/gtest_main.cc
[==========] Running 23 tests from 11 test suites.
[----------] Global test environment set-up.
[----------] 1 test from Tensorvia
[ RUN ] Tensorvia.BasicArithmetic
[ OK ] Tensorvia.BasicArithmetic (0 ms)
[----------] 1 test from Tensorvia (0 ms total)
[----------] 6 tests from View
[ RUN ] View.SliceReadAndInPlaceArithmetic
[ OK ] View.SliceReadAndInPlaceArithmetic (2 ms)
[ RUN ] View.TransposedView
[ OK ] View.TransposedView (0 ms)
[ RUN ] View.CloneAndTypecast
[ OK ] View.CloneAndTypecast (0 ms)
[ RUN ] View.Permute3D
[ OK ] View.Permute3D (0 ms)
[ RUN ] View.InPlaceRejectsNonContiguous
[ OK ] View.InPlaceRejectsNonContiguous (0 ms)
[ RUN ] View.DstBinaryOnTransposedView
[ OK ] View.DstBinaryOnTransposedView (0 ms)
[----------] 6 tests from View (3 ms total)
[----------] 1 test from Tensor
[ RUN ] Tensor.ReferenceSemantics
[ OK ] Tensor.ReferenceSemantics (0 ms)
[----------] 1 test from Tensor (0 ms total)
[----------] 1 test from DType
[ RUN ] DType.MixedPromotion
[ OK ] DType.MixedPromotion (0 ms)
[----------] 1 test from DType (0 ms total)
[----------] 1 test from MatMul
[ RUN ] MatMul.MatchesNaiveGemm
[ OK ] MatMul.MatchesNaiveGemm (57 ms)
[----------] 1 test from MatMul (57 ms total)
[----------] 3 tests from Reduce
[ RUN ] Reduce.ArgmaxArgminIndexType
[ OK ] Reduce.ArgmaxArgminIndexType (0 ms)
[ RUN ] Reduce.OneDimAxis
[ OK ] Reduce.OneDimAxis (0 ms)
[ RUN ] Reduce.ArgmaxTieBreak
[ OK ] Reduce.ArgmaxTieBreak (0 ms)
[----------] 3 tests from Reduce (0 ms total)
[----------] 3 tests from Broadcast
[ RUN ] Broadcast.Arithmetic
[ OK ] Broadcast.Arithmetic (0 ms)
[ RUN ] Broadcast.Comparison
[ OK ] Broadcast.Comparison (0 ms)
[ RUN ] Broadcast.ScalarComparison
[ OK ] Broadcast.ScalarComparison (0 ms)
[----------] 3 tests from Broadcast (0 ms total)
[----------] 1 test from Metadata
[ RUN ] Metadata.DimArray
[ OK ] Metadata.DimArray (0 ms)
[----------] 1 test from Metadata (0 ms total)
[----------] 4 tests from Numeric
[ RUN ] Numeric.Transcendentals
[ OK ] Numeric.Transcendentals (0 ms)
[ RUN ] Numeric.IntegerSoftmax
[ OK ] Numeric.IntegerSoftmax (0 ms)
[ RUN ] Numeric.ReductionsAndSpecialFunctions
[ OK ] Numeric.ReductionsAndSpecialFunctions (0 ms)
[ RUN ] Numeric.NormsAndLosses
[ OK ] Numeric.NormsAndLosses (0 ms)
[----------] 4 tests from Numeric (0 ms total)
[----------] 1 test from Create
[ RUN ] Create.ArangeLinspaceEye
[ OK ] Create.ArangeLinspaceEye (0 ms)
[----------] 1 test from Create (0 ms total)
[----------] 1 test from Indexing
[ RUN ] Indexing.WhereIndexSelectGather
[ OK ] Indexing.WhereIndexSelectGather (0 ms)
[----------] 1 test from Indexing (0 ms total)
[----------] Global test environment tear-down
[==========] 23 tests from 11 test suites ran. (63 ms total)
[ PASSED ] 23 tests.
bench ... ok (0.44s)
add f32 16M 3.035 ms 66.33 GB/s
mul f32 16M 7.189 ms 28.00 GB/s
add-scalar f32 16M 3.127 ms 42.92 GB/s
exp f32 4M 0.342 ms 98.21 GB/s
sum f32 16M 0.660 ms 101.72 GB/s
sum-axis1 4096x4096 0.605 ms 110.96 GB/s
transpose2d 1024x1024 0.205 ms 40.84 GB/s
transpose3d 64^3 0.050 ms 42.08 GB/s
gather permute 128x64x64 1.674 ms 2.50 GB/s
matmul f32 256 0.077 ms 437.73 GFLOPS
matmul f32 512 0.397 ms 675.61 GFLOPS
arange f32 16M 3.726 ms 18.01 GB/s
where f32 16M 5.163 ms 51.99 GB/s
where-scalar f32 16M 3.842 ms 52.40 GB/s
index_select 4096x64 0.022 ms 96.28 GB/s
gather 1024x1024 0.511 ms 24.64 GB/s
layer_norm f32 8192x4096 6.651 ms 80.72 GB/s
rms_norm f32 8192x4096 6.490 ms 62.05 GB/s
randn f32 16M 6.599 ms 10.17 GB/s
mse_loss f32 16M 1.772 ms 75.75 GB/s
nll_loss f32 65536x1024 0.057 ms 4.64 GB/s
cross_entropy f32 8192x256 0.221 ms 152.17 GB/s
test result ok. 2 passed; 0 failed; finished in 64.49s (build 60.79s + run 0.44s)
Metadata
Metadata
Assignees
Labels
No labels
Activity
0.20.0: a SYCL build has one C++ runtime, libstdc++
2026.10.26.1: the control contract, concurrency, and one C++ runtime …
0.20.0: a SYCL build has one C++ runtime; platform plugins (mcpp.plug…