From b0efc764fbe70d793ea2ae542ae1664d845a8da4 Mon Sep 17 00:00:00 2001 From: feixi139 <18210811610@163.com> Date: Wed, 8 Jul 2026 06:46:21 +0000 Subject: [PATCH 01/12] fix bugs fix bugs --- .../kernels/primitive/datamover_primitives.h | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/paddle/phi/kernels/primitive/datamover_primitives.h b/paddle/phi/kernels/primitive/datamover_primitives.h index c357f5142dcd1..2e8f15d36bb02 100644 --- a/paddle/phi/kernels/primitive/datamover_primitives.h +++ b/paddle/phi/kernels/primitive/datamover_primitives.h @@ -40,7 +40,7 @@ struct alignas(sizeof(T) * VecSize) VectorType { * must be [dim1, dim0]. */ struct BroadcastConfig { - funcs::FastDivMod divmoders[DDim::kMaxRank]; + funcs::FastDivMod divmoders[DDim::kMaxRank]; uint64_t strides[DDim::kMaxRank]; int rank{0}; @@ -51,7 +51,7 @@ struct BroadcastConfig { const std::vector& in_dims, int dim_size) { for (int i = 0; i < dim_size; ++i) { - divmoders[i] = funcs::FastDivMod(out_dims[i]); + divmoders[i] = funcs::FastDivMod(out_dims[i]); } for (int i = 0; i < dim_size; ++i) { @@ -59,7 +59,7 @@ struct BroadcastConfig { strides[i] = (i != 0 && strides[i] != 0) ? std::accumulate(in_dims.begin(), in_dims.begin() + i, - 1, + int64_t{1}, std::multiplies()) : strides[i]; } @@ -418,13 +418,15 @@ __device__ __forceinline__ void ReadDataBc( int stride_nx, int stride_ny) { uint32_t thread_offset = block_offset + threadIdx.x; - uint32_t index_src = 0; + int64_t index_src = 0; #pragma unroll for (int ny = 0; ny < NY; ++ny) { #pragma unroll for (uint32_t nx = 0; nx < NX; ++nx) { - uint32_t index_output = thread_offset + ny * stride_ny + nx * stride_nx; + int64_t index_output = thread_offset + + static_cast(ny) * stride_ny + + static_cast(nx) * stride_nx; index_src = 0; if (IsBoundary) { if (index_output >= total_num_output) { @@ -753,11 +755,11 @@ __device__ __forceinline__ void ReadDataBc( int total_num_output, int read_lens = NX) { uint32_t thread_offset = block_offset + threadIdx.x * NX; - uint32_t index_src = 0; + int64_t index_src = 0; #pragma unroll for (uint32_t nx = 0; nx < NX; ++nx) { - uint32_t index_output = thread_offset + nx; + int64_t index_output = thread_offset + nx; index_src = 0; if (IsBoundary) { if (index_output >= total_num_output) { @@ -814,11 +816,11 @@ __device__ __forceinline__ void ReadDataBc( int total_num_output, int read_lens = NX) { uint32_t thread_offset = block_offset + threadIdx.x * NX; - uint32_t index_src = 0; + int64_t index_src = 0; #pragma unroll for (uint32_t nx = 0; nx < NX; ++nx) { - uint32_t index_output = thread_offset + nx; + int64_t index_output = thread_offset + nx; index_src = 0; if (IsBoundary) { if (index_output >= total_num_output) { From bc16d0038e3e5a956aa1d6e8922f2024eea91580 Mon Sep 17 00:00:00 2001 From: feixi139 <18210811610@163.com> Date: Thu, 9 Jul 2026 07:12:39 +0000 Subject: [PATCH 02/12] fix bugs --- .../phi/kernels/primitive/datamover_primitives.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/paddle/phi/kernels/primitive/datamover_primitives.h b/paddle/phi/kernels/primitive/datamover_primitives.h index 2e8f15d36bb02..1c260b4ebe614 100644 --- a/paddle/phi/kernels/primitive/datamover_primitives.h +++ b/paddle/phi/kernels/primitive/datamover_primitives.h @@ -418,15 +418,15 @@ __device__ __forceinline__ void ReadDataBc( int stride_nx, int stride_ny) { uint32_t thread_offset = block_offset + threadIdx.x; - int64_t index_src = 0; + uint64_t index_src = 0; #pragma unroll for (int ny = 0; ny < NY; ++ny) { #pragma unroll for (uint32_t nx = 0; nx < NX; ++nx) { - int64_t index_output = thread_offset + - static_cast(ny) * stride_ny + - static_cast(nx) * stride_nx; + uint64_t index_output = thread_offset + + static_cast(ny) * stride_ny + + static_cast(nx) * stride_nx; index_src = 0; if (IsBoundary) { if (index_output >= total_num_output) { @@ -755,11 +755,11 @@ __device__ __forceinline__ void ReadDataBc( int total_num_output, int read_lens = NX) { uint32_t thread_offset = block_offset + threadIdx.x * NX; - int64_t index_src = 0; + uint64_t index_src = 0; #pragma unroll for (uint32_t nx = 0; nx < NX; ++nx) { - int64_t index_output = thread_offset + nx; + uint64_t index_output = thread_offset + nx; index_src = 0; if (IsBoundary) { if (index_output >= total_num_output) { @@ -816,11 +816,11 @@ __device__ __forceinline__ void ReadDataBc( int total_num_output, int read_lens = NX) { uint32_t thread_offset = block_offset + threadIdx.x * NX; - int64_t index_src = 0; + uint64_t index_src = 0; #pragma unroll for (uint32_t nx = 0; nx < NX; ++nx) { - int64_t index_output = thread_offset + nx; + uint64_t index_output = thread_offset + nx; index_src = 0; if (IsBoundary) { if (index_output >= total_num_output) { From 95f21f79b2f15ce6e0d48551d1b236c70e1d929e Mon Sep 17 00:00:00 2001 From: feixi139 <18210811610@163.com> Date: Thu, 9 Jul 2026 08:03:29 +0000 Subject: [PATCH 03/12] fix bugs --- paddle/phi/kernels/primitive/datamover_primitives.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/paddle/phi/kernels/primitive/datamover_primitives.h b/paddle/phi/kernels/primitive/datamover_primitives.h index 1c260b4ebe614..030114425c748 100644 --- a/paddle/phi/kernels/primitive/datamover_primitives.h +++ b/paddle/phi/kernels/primitive/datamover_primitives.h @@ -414,7 +414,7 @@ __device__ __forceinline__ void ReadDataBc( const T* __restrict__ src, uint32_t block_offset, const details::BroadcastConfig& config, - int total_num_output, + uint64_t total_num_output, int stride_nx, int stride_ny) { uint32_t thread_offset = block_offset + threadIdx.x; @@ -752,7 +752,7 @@ __device__ __forceinline__ void ReadDataBc( const T* __restrict__ src, uint32_t block_offset, const details::BroadcastConfig& config, - int total_num_output, + uint64_t total_num_output, int read_lens = NX) { uint32_t thread_offset = block_offset + threadIdx.x * NX; uint64_t index_src = 0; @@ -813,7 +813,7 @@ __device__ __forceinline__ void ReadDataBc( const T* __restrict__ src, uint32_t block_offset, const details::BroadcastConfig& config, - int total_num_output, + uint64_t total_num_output, int read_lens = NX) { uint32_t thread_offset = block_offset + threadIdx.x * NX; uint64_t index_src = 0; From 54c3fee15a9450a393de485ca3ddeef1213bd302 Mon Sep 17 00:00:00 2001 From: feixi <66367509+feixi139@users.noreply.github.com> Date: Mon, 13 Jul 2026 14:22:58 +0800 Subject: [PATCH 04/12] Update datamover_primitives.h --- paddle/phi/kernels/primitive/datamover_primitives.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/phi/kernels/primitive/datamover_primitives.h b/paddle/phi/kernels/primitive/datamover_primitives.h index 030114425c748..5e6781da52fcc 100644 --- a/paddle/phi/kernels/primitive/datamover_primitives.h +++ b/paddle/phi/kernels/primitive/datamover_primitives.h @@ -1,5 +1,5 @@ // Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at From 1333dd1a3cc2a89811376fdfb19c577094ebd339 Mon Sep 17 00:00:00 2001 From: feixi <66367509+feixi139@users.noreply.github.com> Date: Mon, 13 Jul 2026 14:37:09 +0800 Subject: [PATCH 05/12] Update datamover_primitives.h --- paddle/phi/kernels/primitive/datamover_primitives.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/phi/kernels/primitive/datamover_primitives.h b/paddle/phi/kernels/primitive/datamover_primitives.h index 5e6781da52fcc..030114425c748 100644 --- a/paddle/phi/kernels/primitive/datamover_primitives.h +++ b/paddle/phi/kernels/primitive/datamover_primitives.h @@ -1,5 +1,5 @@ // Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at From ebebd101517ce89879ebb204b510d5fd43c185e0 Mon Sep 17 00:00:00 2001 From: feixi139 <18210811610@163.com> Date: Mon, 13 Jul 2026 08:08:31 +0000 Subject: [PATCH 06/12] fix bugs --- paddle/phi/kernels/funcs/broadcast_function.h | 59 ++++++++++--------- paddle/phi/kernels/funcs/elementwise_base.h | 4 +- .../kernels/primitive/datamover_primitives.h | 12 ++-- 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/paddle/phi/kernels/funcs/broadcast_function.h b/paddle/phi/kernels/funcs/broadcast_function.h index 1dabfeb425793..a6c8841870194 100644 --- a/paddle/phi/kernels/funcs/broadcast_function.h +++ b/paddle/phi/kernels/funcs/broadcast_function.h @@ -120,9 +120,9 @@ struct BroadcastDataLoader { ArgsT *args, const Array2 &configs, const Array3 &use_broadcast, - const int block_offset, + uint64_t block_offset, const int num, - const uint32_t numel, + uint64_t numel, int read_lens) { using Type = std::tuple_element_t; #ifdef PADDLE_WITH_XPU_KP @@ -178,16 +178,17 @@ struct BroadcastDataLoader { ArgsT *args, const Array2 &configs, const Array3 &use_broadcast, - const int block_offset, + uint64_t block_offset, const int num, - const uint32_t numel, + uint64_t numel, int read_lens) { using Type = std::tuple_element_t; - int thread_offset = threadIdx.x * VecSize + block_offset; + uint64_t thread_offset = + static_cast(threadIdx.x) * VecSize + block_offset; #pragma unroll for (int idx = 0; idx < VecSize; ++idx) { std::get(args[idx]) = static_cast(1); - int index = thread_offset + idx; + uint64_t index = thread_offset + idx; if (index < numel) { std::get(args[idx]) = reinterpret_cast(ins[Index])[index]; @@ -204,9 +205,9 @@ struct BroadcastDataLoader { ArgsT *args, const Array2 &configs, const Array3 &use_broadcast, - const int block_offset, + uint64_t block_offset, const int num, - const uint32_t numel, + uint64_t numel, int read_lens) { using Type = std::tuple_element_t; using VecType = phi::kps::details::VectorType; @@ -242,7 +243,7 @@ struct BroadcastDataSetter { template static __device__ __forceinline__ void Apply(const Array &ins, ArgsT *args, - uint32_t index_bc[][VecSize]) { + uint64_t index_bc[][VecSize]) { using Type = std::tuple_element_t; #pragma unroll for (int k = 0; k < VecSize; ++k) { @@ -294,10 +295,10 @@ __device__ void VectorizedBroadcastKernelImpl( const Array &ins, Array<_ptr_ OutT *, NumOuts> outs, const Array &use_broadcast, - const uint32_t numel, + const uint64_t numel, const Array &configs, uint32_t num, - uint32_t block_offset, + uint64_t block_offset, int read_lens, Functor func) { using Traits = funcs::FunctionTraits; @@ -310,12 +311,12 @@ __device__ void VectorizedBroadcastKernelImpl( ins, args, configs, use_broadcast, block_offset, num, numel, read_lens); #else if (LoadType == kBroadcast) { - uint32_t index_bc[Arity][VecSize] = {0}; + uint64_t index_bc[Arity][VecSize] = {0}; Unroller::step(args); - uint32_t thread_offset = block_offset + threadIdx.x * VecSize; + uint64_t thread_offset = block_offset + threadIdx.x * VecSize; #pragma unroll for (int k = 0; k < VecSize; ++k) { - uint32_t idx = thread_offset + k; + uint64_t idx = thread_offset + k; if (IsBoundary && idx == numel) break; #pragma unroll for (int i = 0; i < DDim::kMaxRank; ++i) { @@ -353,15 +354,16 @@ __global__ void VectorizedBroadcastKernel( Array ins, Array<_ptr_ OutT *, NumOuts> outs, Array use_broadcast, - uint32_t numel, + uint64_t numel, Array configs, - uint32_t main_offset, - uint32_t tail_tid, + uint64_t main_offset, + uint64_t tail_tid, int read_lens, Functor func) { #ifdef PADDLE_WITH_XPU_KP - int64_t block_offset = BLOCK_ID_X * BLOCK_NUM_X * read_lens; - int64_t stride = BLOCK_NUM_X * GRID_NUM_X * read_lens; + uint64_t block_offset = + static_cast(BLOCK_ID_X) * BLOCK_NUM_X * read_lens; + uint64_t stride = static_cast(BLOCK_NUM_X) * GRID_NUM_X * read_lens; for (; block_offset < main_offset; block_offset += stride) { VectorizedBroadcastKernelImpl 0) { VectorizedBroadcastKernelImpl(BLOCK_ID_X) * BLOCK_NUM_X * VecSize; if (block_offset < main_offset) { VectorizedBroadcastKernelImpl &classifier, Functor func) { #ifdef PADDLE_WITH_XPU_KP - int numel = classifier.numel; + const int64_t numel = classifier.numel; const int threads = 64; const int blocks = 8; int read_lens = configs[0].buf_len; auto stream = dev_ctx.x_context()->xpu_stream; - uint32_t main_offset = (numel / (read_lens * threads)) * read_lens * threads; - uint32_t tail_tid = numel % (read_lens * threads); + const int64_t block_len = static_cast(read_lens) * threads; + const int64_t main_offset = (numel / block_len) * block_len; + const int64_t tail_tid = numel % block_len; VectorizedBroadcastKernel <<>>(classifier.ins_data, @@ -460,14 +464,15 @@ void LaunchBroadcastKernel( read_lens, func); #else - const int64_t &numel = classifier.numel; + const int64_t numel = classifier.numel; auto gpu_config = phi::backends::gpu::GetGpuLaunchConfig1D(dev_ctx, numel, VecSize); auto stream = dev_ctx.stream(); auto threads = gpu_config.GetBlockSize(); auto blocks = gpu_config.block_per_grid; - uint32_t main_offset = (numel / (VecSize * threads)) * VecSize * threads; - uint32_t tail_tid = numel % (VecSize * threads); + const int64_t block_len = static_cast(VecSize) * threads; + const int64_t main_offset = (numel / block_len) * block_len; + const int64_t tail_tid = numel % block_len; if (classifier.all_elementwise) { VectorizedBroadcastKernel outs, ConditionalT src[VecSize], - kps::IndexType block_offset, + int64_t block_offset, int num, int read_lens) { OutT dst[NumOuts][VecSize]; @@ -702,7 +702,7 @@ template struct ElementwiseWriteDataCallerBc { __device__ __forceinline__ void operator()(Array<_ptr_ OutT *, 1> outs, OutT src[VecSize], - kps::IndexType block_offset, + int64_t block_offset, int num, int read_lens) { kps::WriteData( diff --git a/paddle/phi/kernels/primitive/datamover_primitives.h b/paddle/phi/kernels/primitive/datamover_primitives.h index 030114425c748..c0d7f1ae7bb88 100644 --- a/paddle/phi/kernels/primitive/datamover_primitives.h +++ b/paddle/phi/kernels/primitive/datamover_primitives.h @@ -412,12 +412,12 @@ template __device__ __forceinline__ void ReadDataBc( T* dst, const T* __restrict__ src, - uint32_t block_offset, + uint64_t block_offset, const details::BroadcastConfig& config, uint64_t total_num_output, int stride_nx, int stride_ny) { - uint32_t thread_offset = block_offset + threadIdx.x; + uint64_t thread_offset = block_offset + threadIdx.x; uint64_t index_src = 0; #pragma unroll @@ -750,11 +750,11 @@ template __device__ __forceinline__ void ReadDataBc( T* dst, const T* __restrict__ src, - uint32_t block_offset, + uint64_t block_offset, const details::BroadcastConfig& config, uint64_t total_num_output, int read_lens = NX) { - uint32_t thread_offset = block_offset + threadIdx.x * NX; + uint64_t thread_offset = block_offset + threadIdx.x * NX; uint64_t index_src = 0; #pragma unroll @@ -811,11 +811,11 @@ template Date: Mon, 13 Jul 2026 08:30:18 +0000 Subject: [PATCH 07/12] fix bugs --- paddle/phi/kernels/funcs/broadcast_function.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/paddle/phi/kernels/funcs/broadcast_function.h b/paddle/phi/kernels/funcs/broadcast_function.h index a6c8841870194..2f21f653a9c60 100644 --- a/paddle/phi/kernels/funcs/broadcast_function.h +++ b/paddle/phi/kernels/funcs/broadcast_function.h @@ -15,6 +15,7 @@ limitations under the License. */ #pragma once #include +#include "paddle/common/enforce.h" #include "paddle/phi/kernels/funcs/elementwise_base.h" #if defined(__NVCC__) || defined(__HIPCC__) || defined(__xpu__) @@ -381,8 +382,8 @@ __global__ void VectorizedBroadcastKernel( read_lens, func); } - uint64_t num = numel - block_offset; - if (num > 0) { + if (block_offset < numel) { + uint64_t num = numel - block_offset; VectorizedBroadcastKernelImpl Date: Mon, 13 Jul 2026 09:24:10 +0000 Subject: [PATCH 08/12] fix bugs --- paddle/phi/kernels/funcs/broadcast_function.h | 11 ++++++++--- paddle/phi/kernels/primitive/datamover_primitives.h | 8 +++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/paddle/phi/kernels/funcs/broadcast_function.h b/paddle/phi/kernels/funcs/broadcast_function.h index 2f21f653a9c60..525b52f3551b0 100644 --- a/paddle/phi/kernels/funcs/broadcast_function.h +++ b/paddle/phi/kernels/funcs/broadcast_function.h @@ -48,7 +48,12 @@ struct BroadcastTypeClassifier { int axis) { numel = (*outs)[0]->numel(); -#ifndef PADDLE_WITH_XPU_KP +#ifdef PADDLE_WITH_XPU_KP + // datamover_primitives_xpu2.h::BroadcastConfig (built inside + // InitBroadcastConfigs below) still computes strides/numel with 32-bit + // int, so the INT_MAX check must happen before that call, not after. + PADDLE_ENFORCE_LE_INT_MAX(numel, "BroadcastKernel numel (XPU)"); +#else for (size_t i = 0; i < ins.size(); ++i) { bool is_same_dim = ins[i]->numel() == numel; if (is_same_dim) { @@ -314,7 +319,8 @@ __device__ void VectorizedBroadcastKernelImpl( if (LoadType == kBroadcast) { uint64_t index_bc[Arity][VecSize] = {0}; Unroller::step(args); - uint64_t thread_offset = block_offset + threadIdx.x * VecSize; + uint64_t thread_offset = + block_offset + static_cast(threadIdx.x) * VecSize; #pragma unroll for (int k = 0; k < VecSize; ++k) { uint64_t idx = thread_offset + k; @@ -446,7 +452,6 @@ void LaunchBroadcastKernel( Functor func) { #ifdef PADDLE_WITH_XPU_KP const int64_t numel = classifier.numel; - PADDLE_ENFORCE_LE_INT_MAX(numel, "BroadcastKernel numel (XPU)"); const int threads = 64; const int blocks = 8; int read_lens = configs[0].buf_len; diff --git a/paddle/phi/kernels/primitive/datamover_primitives.h b/paddle/phi/kernels/primitive/datamover_primitives.h index c0d7f1ae7bb88..c8bfd42f11cf0 100644 --- a/paddle/phi/kernels/primitive/datamover_primitives.h +++ b/paddle/phi/kernels/primitive/datamover_primitives.h @@ -417,7 +417,7 @@ __device__ __forceinline__ void ReadDataBc( uint64_t total_num_output, int stride_nx, int stride_ny) { - uint64_t thread_offset = block_offset + threadIdx.x; + uint64_t thread_offset = block_offset + static_cast(threadIdx.x); uint64_t index_src = 0; #pragma unroll @@ -754,7 +754,8 @@ __device__ __forceinline__ void ReadDataBc( const details::BroadcastConfig& config, uint64_t total_num_output, int read_lens = NX) { - uint64_t thread_offset = block_offset + threadIdx.x * NX; + uint64_t thread_offset = + block_offset + static_cast(threadIdx.x) * NX; uint64_t index_src = 0; #pragma unroll @@ -815,7 +816,8 @@ __device__ __forceinline__ void ReadDataBc( const details::BroadcastConfig& config, uint64_t total_num_output, int read_lens = NX) { - uint64_t thread_offset = block_offset + threadIdx.x * NX; + uint64_t thread_offset = + block_offset + static_cast(threadIdx.x) * NX; uint64_t index_src = 0; #pragma unroll From 6848e24d263172dbae7a424462b4a4b8f5dd15d8 Mon Sep 17 00:00:00 2001 From: feixi139 <18210811610@163.com> Date: Wed, 15 Jul 2026 06:55:05 +0000 Subject: [PATCH 09/12] fix bugs --- paddle/phi/kernels/funcs/broadcast_function.h | 284 +++++++++++------- paddle/phi/kernels/funcs/elementwise_base.h | 4 +- .../kernels/primitive/datamover_primitives.h | 35 ++- 3 files changed, 202 insertions(+), 121 deletions(-) diff --git a/paddle/phi/kernels/funcs/broadcast_function.h b/paddle/phi/kernels/funcs/broadcast_function.h index 525b52f3551b0..ef23bf789b946 100644 --- a/paddle/phi/kernels/funcs/broadcast_function.h +++ b/paddle/phi/kernels/funcs/broadcast_function.h @@ -14,6 +14,7 @@ limitations under the License. */ #pragma once +#include #include #include "paddle/common/enforce.h" #include "paddle/phi/kernels/funcs/elementwise_base.h" @@ -119,16 +120,20 @@ struct BroadcastTypeClassifier { }; // Common broadcast/elementwise Loader. -template +template struct BroadcastDataLoader { template static __device__ __forceinline__ void Apply(const Array1 &ins, ArgsT *args, const Array2 &configs, const Array3 &use_broadcast, - uint64_t block_offset, + IndexT block_offset, const int num, - uint64_t numel, + IndexT numel, int read_lens) { using Type = std::tuple_element_t; #ifdef PADDLE_WITH_XPU_KP @@ -152,7 +157,7 @@ struct BroadcastDataLoader { #else kps::Init(args, static_cast(1.0f)); if (use_broadcast[Index]) { - kps::ReadDataBc( + kps::ReadDataBc( args, reinterpret_cast(ins[Index]), block_offset, @@ -177,24 +182,24 @@ struct BroadcastDataLoader { /* BroadcastDataLoaders Partial specialization */ #ifndef PADDLE_WITH_XPU_KP // Scalar elementwise Loader with consideration of IsBoundary. -template -struct BroadcastDataLoader { +template +struct BroadcastDataLoader { template static __device__ __forceinline__ void Apply(const Array1 &ins, ArgsT *args, const Array2 &configs, const Array3 &use_broadcast, - uint64_t block_offset, + IndexT block_offset, const int num, - uint64_t numel, + IndexT numel, int read_lens) { using Type = std::tuple_element_t; - uint64_t thread_offset = - static_cast(threadIdx.x) * VecSize + block_offset; + IndexT thread_offset = + static_cast(threadIdx.x) * VecSize + block_offset; #pragma unroll for (int idx = 0; idx < VecSize; ++idx) { std::get(args[idx]) = static_cast(1); - uint64_t index = thread_offset + idx; + IndexT index = thread_offset + idx; if (index < numel) { std::get(args[idx]) = reinterpret_cast(ins[Index])[index]; @@ -204,24 +209,23 @@ struct BroadcastDataLoader { }; // Vectorized elementwise Loader without consideration of IsBoundary. -template -struct BroadcastDataLoader { +template +struct BroadcastDataLoader { template static __device__ __forceinline__ void Apply(const Array1 &ins, ArgsT *args, const Array2 &configs, const Array3 &use_broadcast, - uint64_t block_offset, + IndexT block_offset, const int num, - uint64_t numel, + IndexT numel, int read_lens) { using Type = std::tuple_element_t; using VecType = phi::kps::details::VectorType; VecType vec_temp; - int64_t thread_offset = - static_cast(threadIdx.x) + - static_cast(blockIdx.x) * static_cast(blockDim.x); + IndexT thread_offset = + block_offset / VecSize + static_cast(threadIdx.x); const VecType *__restrict__ vec_input = reinterpret_cast(ins[Index]); vec_temp = vec_input[thread_offset]; @@ -262,8 +266,13 @@ struct BroadcastDataSetter { #endif // static broadcast unroller -template