From 132fffe0357380162f83d4492561892918e0aa4a Mon Sep 17 00:00:00 2001 From: dengyingxu1 Date: Tue, 28 Jul 2026 22:21:51 +0800 Subject: [PATCH] test: init npu python runtime in triton test main entries. Each triton_npu gtest binary owns its own main() to probe NPU availability, so the global test environment registered in tests/npu_test_environment.cpp cannot run first deterministically. Call xllm::testing::init_npu_test_runtime() right after InitGoogleTest so aclInit, Py_InitializeEx and torch_npu import happen before any NPU API is touched, matching the guidance in npu_test_environment.h. --- triton_npu/test/triton_causal_conv1d_update_test.cpp | 2 ++ triton_npu/test/triton_causal_conv1d_update_v2_test.cpp | 2 ++ triton_npu/test/triton_chunk_gated_delta_rule_test.cpp | 2 ++ triton_npu/test/triton_fused_gdn_gating_test.cpp | 2 ++ triton_npu/test/triton_fused_qkvzba_split_reshape_test.cpp | 2 ++ triton_npu/test/triton_l2norm_test.cpp | 2 ++ triton_npu/test/triton_layernorm_fwd_test.cpp | 2 ++ triton_npu/test/triton_recurrent_gated_delta_rule_test.cpp | 2 ++ triton_npu/test/triton_rope_inplace_test.cpp | 2 ++ triton_npu/test/triton_split_rmsnorm_rope_test.cpp | 2 ++ 10 files changed, 20 insertions(+) diff --git a/triton_npu/test/triton_causal_conv1d_update_test.cpp b/triton_npu/test/triton_causal_conv1d_update_test.cpp index a6a27b5..834f2c9 100644 --- a/triton_npu/test/triton_causal_conv1d_update_test.cpp +++ b/triton_npu/test/triton_causal_conv1d_update_test.cpp @@ -25,6 +25,7 @@ #include "kernel_registry.h" #include "test/test_utils.h" +#include "tests/npu_test_environment.h" #include "torch_api/triton_ops_api.h" #include "torch_npu/csrc/core/npu/NPUCachingAllocator.h" @@ -253,6 +254,7 @@ TEST_F(TritonCausalConv1dUpdateTest, MultiBatchTest) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); + xllm::testing::init_npu_test_runtime(); bool npu_available = false; std::string device_str = diff --git a/triton_npu/test/triton_causal_conv1d_update_v2_test.cpp b/triton_npu/test/triton_causal_conv1d_update_v2_test.cpp index 487363f..c1e1e03 100644 --- a/triton_npu/test/triton_causal_conv1d_update_v2_test.cpp +++ b/triton_npu/test/triton_causal_conv1d_update_v2_test.cpp @@ -26,6 +26,7 @@ #include "kernel_registry.h" #include "test/test_utils.h" +#include "tests/npu_test_environment.h" #include "torch_api/triton_ops_api.h" #include "torch_npu/csrc/core/npu/NPUCachingAllocator.h" @@ -511,5 +512,6 @@ TEST_F(TritonCausalConv1dUpdateV2Test, VarlenPadWidth5Test) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); + xllm::testing::init_npu_test_runtime(); return RUN_ALL_TESTS(); } diff --git a/triton_npu/test/triton_chunk_gated_delta_rule_test.cpp b/triton_npu/test/triton_chunk_gated_delta_rule_test.cpp index 193888f..f454338 100644 --- a/triton_npu/test/triton_chunk_gated_delta_rule_test.cpp +++ b/triton_npu/test/triton_chunk_gated_delta_rule_test.cpp @@ -34,6 +34,7 @@ #include "kernel_registry.h" #include "test/test_utils.h" +#include "tests/npu_test_environment.h" #include "torch_api/triton_ops_api.h" #include "torch_npu/csrc/core/npu/NPUCachingAllocator.h" @@ -603,6 +604,7 @@ INSTANTIATE_TEST_SUITE_P( int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); + xllm::testing::init_npu_test_runtime(); bool npu_available = false; std::string device_str = diff --git a/triton_npu/test/triton_fused_gdn_gating_test.cpp b/triton_npu/test/triton_fused_gdn_gating_test.cpp index d7ead29..4a37972 100644 --- a/triton_npu/test/triton_fused_gdn_gating_test.cpp +++ b/triton_npu/test/triton_fused_gdn_gating_test.cpp @@ -24,6 +24,7 @@ #include "kernel_registry.h" #include "test/test_utils.h" +#include "tests/npu_test_environment.h" #include "torch_api/triton_ops_api.h" #include "torch_npu/csrc/core/npu/NPUCachingAllocator.h" @@ -166,6 +167,7 @@ TEST_F(TritonFusedGdnGatingTest, DecodeKernelTest) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); + xllm::testing::init_npu_test_runtime(); bool npu_available = false; std::string device_str = diff --git a/triton_npu/test/triton_fused_qkvzba_split_reshape_test.cpp b/triton_npu/test/triton_fused_qkvzba_split_reshape_test.cpp index dffb15b..a258085 100644 --- a/triton_npu/test/triton_fused_qkvzba_split_reshape_test.cpp +++ b/triton_npu/test/triton_fused_qkvzba_split_reshape_test.cpp @@ -31,6 +31,7 @@ #include "kernel_registry.h" #include "test/test_utils.h" +#include "tests/npu_test_environment.h" #include "torch_api/triton_ops_api.h" #include "torch_npu/csrc/core/npu/NPUCachingAllocator.h" @@ -283,6 +284,7 @@ INSTANTIATE_TEST_SUITE_P( int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); + xllm::testing::init_npu_test_runtime(); bool npu_available = false; std::string device_str = diff --git a/triton_npu/test/triton_l2norm_test.cpp b/triton_npu/test/triton_l2norm_test.cpp index 0efb9b5..e5091de 100644 --- a/triton_npu/test/triton_l2norm_test.cpp +++ b/triton_npu/test/triton_l2norm_test.cpp @@ -24,6 +24,7 @@ #include "kernel_registry.h" #include "test/test_utils.h" +#include "tests/npu_test_environment.h" #include "torch_api/triton_ops_api.h" namespace xllm::kernel::npu { @@ -130,6 +131,7 @@ INSTANTIATE_TEST_SUITE_P( int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); + xllm::testing::init_npu_test_runtime(); bool npu_available = false; std::string device_str = diff --git a/triton_npu/test/triton_layernorm_fwd_test.cpp b/triton_npu/test/triton_layernorm_fwd_test.cpp index 6fbc0ab..d96435c 100644 --- a/triton_npu/test/triton_layernorm_fwd_test.cpp +++ b/triton_npu/test/triton_layernorm_fwd_test.cpp @@ -26,6 +26,7 @@ #include "kernel_registry.h" #include "test/test_utils.h" +#include "tests/npu_test_environment.h" #include "torch_api/triton_ops_api.h" #include "torch_npu/csrc/core/npu/NPUCachingAllocator.h" @@ -341,6 +342,7 @@ TEST_F(TritonLayerNormFwdTest, KernelTestFastRMSBF16ZNoBiasNoMask) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); + xllm::testing::init_npu_test_runtime(); bool npu_available = false; std::string device_str = diff --git a/triton_npu/test/triton_recurrent_gated_delta_rule_test.cpp b/triton_npu/test/triton_recurrent_gated_delta_rule_test.cpp index edde005..cdfd2d4 100644 --- a/triton_npu/test/triton_recurrent_gated_delta_rule_test.cpp +++ b/triton_npu/test/triton_recurrent_gated_delta_rule_test.cpp @@ -24,6 +24,7 @@ #include "kernel_registry.h" #include "test/test_utils.h" +#include "tests/npu_test_environment.h" #include "torch_api/triton_ops_api.h" #include "torch_npu/csrc/core/npu/NPUCachingAllocator.h" @@ -570,6 +571,7 @@ TEST_F(TritonRecurrentGatedDeltaRuleTest, SpecAccuracyTp4LocalShape) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); + xllm::testing::init_npu_test_runtime(); bool npu_available = false; std::string device_str = diff --git a/triton_npu/test/triton_rope_inplace_test.cpp b/triton_npu/test/triton_rope_inplace_test.cpp index 40932e3..5c9cb9b 100644 --- a/triton_npu/test/triton_rope_inplace_test.cpp +++ b/triton_npu/test/triton_rope_inplace_test.cpp @@ -23,6 +23,7 @@ #include "kernel_registry.h" #include "test/test_utils.h" +#include "tests/npu_test_environment.h" #include "torch_api/triton_ops_api.h" #include "torch_npu/csrc/core/npu/NPUCachingAllocator.h" @@ -200,6 +201,7 @@ INSTANTIATE_TEST_SUITE_P(RopeInplaceParams, int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); + xllm::testing::init_npu_test_runtime(); bool npu_available = false; std::string device_str = diff --git a/triton_npu/test/triton_split_rmsnorm_rope_test.cpp b/triton_npu/test/triton_split_rmsnorm_rope_test.cpp index 75e60c6..f20e96e 100644 --- a/triton_npu/test/triton_split_rmsnorm_rope_test.cpp +++ b/triton_npu/test/triton_split_rmsnorm_rope_test.cpp @@ -28,6 +28,7 @@ #include "kernel_registry.h" #include "test/test_utils.h" +#include "tests/npu_test_environment.h" #include "torch_api/triton_ops_api.h" #include "torch_npu/csrc/core/npu/NPUCachingAllocator.h" @@ -262,6 +263,7 @@ TEST_F(TritonSplitRmsnormRopeTest, RandomInputMatchesCpuReference) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); + xllm::testing::init_npu_test_runtime(); return RUN_ALL_TESTS(); }