已合并
round_size pad 32 byte #28329
zhaoyu65创建于 2025年12月19日
round_size pad 32 byte #28329
已合并
zhaoyu65创建于 2025年12月19日
共 2 个文件变更+1-26
@@ -73,16 +73,6 @@ class Test_roundup_power2_divisions(TestCase):
73 self.assertEqual(allocated_bytes, active_bytes)73 self.assertEqual(allocated_bytes, active_bytes)
74 self.assertEqual(allocated_bytes, 1024)74 self.assertEqual(allocated_bytes, 1024)
75 75 
76- @SupportedDevices(['Ascend910B', 'Ascend910C'])
77- def test_without_add_32(self):
78- torch.npu.memory.empty_cache()
79- 
80- x = torch.from_numpy(np.random.randn(512).astype(np.uint8)).to("npu")
81- allocated_bytes = torch.npu.memory_stats()["allocated_bytes.all.current"]
82- active_bytes = torch.npu.memory_stats()["active_bytes.all.current"]
83- self.assertEqual(allocated_bytes, active_bytes)
84- self.assertEqual(allocated_bytes, 512)
85- 
86 76 
87if __name__ == '__main__':77if __name__ == '__main__':
88 run_tests()78 run_tests()
@@ -1992,19 +1992,6 @@ public:
1992 return result;1992 return result;
1993 }1993 }
1994 1994 
1995- static bool should_apply_legacy_round_padding()
1996- {
1997- static bool should_pad = []() -> bool {
1998- const auto &soc_version = c10_npu::GetSocVersion();
1999- const bool disable_padding =
2000- (soc_version >= c10_npu::SocVersion::Ascend910B1 &&
2001- soc_version <= c10_npu::SocVersion::Ascend910B4_1) ||
2002- (soc_version >= c10_npu::SocVersion::Ascend910_9391);
2003- return !disable_padding;
2004- }();
2005- return should_pad;
2006- }
2007- 
2008 // This function takes the size and number of divisions argument and rounds1995 // This function takes the size and number of divisions argument and rounds
2009 // up the size argument for the nearest power-of-2 division.1996 // up the size argument for the nearest power-of-2 division.
2010 // For example, if we need to round-up 1200 and number of divisions is 4,1997 // For example, if we need to round-up 1200 and number of divisions is 4,
@@ -2035,9 +2022,7 @@ public:
2035 static size_t round_size(size_t size)2022 static size_t round_size(size_t size)
2036 {2023 {
2037 constexpr size_t kPadSize = 32;2024 constexpr size_t kPadSize = 32;
2038- if (should_apply_legacy_round_padding()) {2025+ size += kPadSize;
2039- size += kPadSize;
2040- }
2041 2026 
2042 if (size < kMinBlockSize) {2027 if (size < kMinBlockSize) {
2043 return kMinBlockSize;2028 return kMinBlockSize;