From 6014ea08c6171c62c2a12956a3cf2162be0b6836 Mon Sep 17 00:00:00 2001 From: stevemcgregory Date: Sat, 16 Aug 2025 09:16:35 -0500 Subject: [PATCH] Fix shared memory alignment in concat/split GPU kernels Align shared memory buffer to 16 bytes (or max of T and IntType) to avoid misaligned access issues on newer GPUs. --- tensorflow/core/kernels/concat_lib_gpu_impl.cu.cc | 5 ++++- tensorflow/core/kernels/split_lib_gpu.cu.cc | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tensorflow/core/kernels/concat_lib_gpu_impl.cu.cc b/tensorflow/core/kernels/concat_lib_gpu_impl.cu.cc index 031464dfdd9ca20c99dea34cd99733046da4d19a..a6cece16d20ddf91536ba82ce8b03af4c2c5b5d6 100644 --- a/tensorflow/core/kernels/concat_lib_gpu_impl.cu.cc +++ b/tensorflow/core/kernels/concat_lib_gpu_impl.cu.cc @@ -70,7 +70,10 @@ __global__ void concat_variable_kernel( IntType num_inputs = input_ptr_data.size; // verbose declaration needed due to template - GPU_DYNAMIC_SHARED_MEM_DECL(sizeof(T), unsigned char, smem); + constexpr size_t kAlignTI = + (alignof(T) > alignof(IntType)) ? alignof(T) : alignof(IntType); + constexpr size_t kAlign = (kAlignTI < 16) ? 16 : kAlignTI; + GPU_DYNAMIC_SHARED_MEM_DECL(kAlign, unsigned char, smem); IntType* smem_col_scan = reinterpret_cast(smem); if (useSmem) { diff --git a/tensorflow/core/kernels/split_lib_gpu.cu.cc b/tensorflow/core/kernels/split_lib_gpu.cu.cc index 90b28292ac074851a785f4aba304182292737b94..b55845bb4e9f6f31a0aa1e81b5524d8ef39ce801 100644 --- a/tensorflow/core/kernels/split_lib_gpu.cu.cc +++ b/tensorflow/core/kernels/split_lib_gpu.cu.cc @@ -120,7 +120,10 @@ __global__ void split_v_kernel(const T* __restrict__ input_ptr, int num_outputs = output_ptr_data.size; // verbose declaration needed due to template - GPU_DYNAMIC_SHARED_MEM_DECL(sizeof(T), unsigned char, smem); + constexpr size_t kAlignTI = + (alignof(T) > alignof(IntType)) ? alignof(T) : alignof(IntType); + constexpr size_t kAlign = (kAlignTI < 16) ? 16 : kAlignTI; + GPU_DYNAMIC_SHARED_MEM_DECL(kAlign, unsigned char, smem); IntType* smem_col_scan = reinterpret_cast(smem); if (useSmem) {