[Bugfix][Kernel] Fix integer overflow in libtorch_stable/activation_kernels.cu (#49660)
Signed-off-by: molly-ting <molly.cn.mail@gmail.com> Co-authored-by: Michael Goin <mgoin64@gmail.com>
This commit is contained in:
@@ -103,9 +103,10 @@ __global__ void act_and_mul_kernel(
|
|||||||
scalar_t* __restrict__ out, // [..., d]
|
scalar_t* __restrict__ out, // [..., d]
|
||||||
const scalar_t* __restrict__ input, // [..., 2, d]
|
const scalar_t* __restrict__ input, // [..., 2, d]
|
||||||
const int d, const float limit, const float alpha, const float beta) {
|
const int d, const float limit, const float alpha, const float beta) {
|
||||||
const scalar_t* x_ptr = input + blockIdx.x * 2 * d;
|
const int64_t token_idx = blockIdx.x;
|
||||||
|
const scalar_t* x_ptr = input + token_idx * 2 * d;
|
||||||
const scalar_t* y_ptr = x_ptr + d;
|
const scalar_t* y_ptr = x_ptr + d;
|
||||||
scalar_t* out_ptr = out + blockIdx.x * d;
|
scalar_t* out_ptr = out + token_idx * d;
|
||||||
|
|
||||||
if constexpr (use_vec) {
|
if constexpr (use_vec) {
|
||||||
using cuda_t = typename CUDATypeConverter<scalar_t>::Type;
|
using cuda_t = typename CUDATypeConverter<scalar_t>::Type;
|
||||||
@@ -353,9 +354,10 @@ template <typename scalar_t, typename packed_t,
|
|||||||
__global__ void act_and_mul_kernel_with_param(
|
__global__ void act_and_mul_kernel_with_param(
|
||||||
scalar_t* __restrict__ out, const scalar_t* __restrict__ input, const int d,
|
scalar_t* __restrict__ out, const scalar_t* __restrict__ input, const int d,
|
||||||
const float param) {
|
const float param) {
|
||||||
const scalar_t* x_ptr = input + blockIdx.x * 2 * d;
|
const int64_t token_idx = blockIdx.x;
|
||||||
|
const scalar_t* x_ptr = input + token_idx * 2 * d;
|
||||||
const scalar_t* y_ptr = x_ptr + d;
|
const scalar_t* y_ptr = x_ptr + d;
|
||||||
scalar_t* out_ptr = out + blockIdx.x * d;
|
scalar_t* out_ptr = out + token_idx * d;
|
||||||
|
|
||||||
if constexpr (use_vec) {
|
if constexpr (use_vec) {
|
||||||
using cuda_t = typename CUDATypeConverter<scalar_t>::Type;
|
using cuda_t = typename CUDATypeConverter<scalar_t>::Type;
|
||||||
@@ -670,8 +672,9 @@ __global__ void activation_kernel(
|
|||||||
scalar_t* __restrict__ out, // [..., d]
|
scalar_t* __restrict__ out, // [..., d]
|
||||||
const scalar_t* __restrict__ input, // [..., d]
|
const scalar_t* __restrict__ input, // [..., d]
|
||||||
const int d) {
|
const int d) {
|
||||||
const scalar_t* in_ptr = input + blockIdx.x * d;
|
const int64_t token_idx = blockIdx.x;
|
||||||
scalar_t* out_ptr = out + blockIdx.x * d;
|
const scalar_t* in_ptr = input + token_idx * d;
|
||||||
|
scalar_t* out_ptr = out + token_idx * d;
|
||||||
|
|
||||||
if constexpr (use_vec) {
|
if constexpr (use_vec) {
|
||||||
// Fast path: 128-bit/256-bit vectorized loop
|
// Fast path: 128-bit/256-bit vectorized loop
|
||||||
|
|||||||
Reference in New Issue
Block a user