[CUDA][srad_v2] Out-of-bounds neighbor reads occur before boundary correction

Abierto Apto para principiantes
#12 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c
Área
hpc

Línea de trabajo

Comienza en cuda/srad_v2/srad_kernel.cu, en srad_cuda_1 y srad_cuda_2, siguiendo index_n e index_s a través de las ramas de los límites. Verifica que, antes de la corrección, ninguna carga de un vecino pueda acceder fuera de la asignación de rows * cols; después, valida el resultado con las pruebas de seguridad de memoria del repositorio.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

The srad_v2 CUDA implementation in this repository contains global-memory out-of-bounds reads in srad_cuda_1 and srad_cuda_2.

The kernels compute neighbor indices and immediately use them to load data from global memory. For boundary blocks, some of these indices fall outside the underlying allocation. The code only replaces the corresponding shared-memory values with valid boundary values after the
loads have already occurred.

I detected these invalid reads during memory-safety testing and subsequently confirmed the issue from the source-level index calculations.

Affected Code

File: cuda/srad_v2/srad_kernel.cu

In srad_cuda_1, neighbor values are loaded before the boundary condition is handled:

north[ty][tx] = J_cuda[index_n];
south[ty][tx] = J_cuda[index_s];

if (by == 0) {
    north[ty][tx] = J_cuda[BLOCK_SIZE * bx + tx];
} else if (by == gridDim.y - 1) {
    south[ty][tx] =
        J_cuda[cols * BLOCK_SIZE * (gridDim.y - 1)
             + BLOCK_SIZE * bx
             + cols * (BLOCK_SIZE - 1) + tx];
}

A similar pattern occurs in srad_cuda_2:

south_c[ty][tx] = C_cuda[index_s];

if (by == gridDim.y - 1) {
    south_c[ty][tx] =
        C_cuda[cols * BLOCK_SIZE * (gridDim.y - 1)
             + BLOCK_SIZE * bx
             + cols * (BLOCK_SIZE - 1) + tx];
}

Root Cause

The device arrays contain exactly:

rows * cols

elements, so the valid index range is:

0 ... rows * cols - 1

For the top block row (by == 0), index_n is negative, causing a read before the beginning of J_cuda.

For the bottom block row (by == gridDim.y - 1), the south-neighbor index satisfies:

index_s >= rows * cols

and therefore accesses memory beyond the end of the allocation.

For example, with:

rows = 128

cols = 128

the allocation contains:

128 * 128 = 16384

floating-point elements, corresponding to:

16384 * sizeof(float) = 65536 bytes

The first invalid south-neighbor access can therefore occur at:

base + 65536

which is exactly the first address beyond the allocation.

The later boundary correction only overwrites the value stored in shared memory. It cannot undo the out-of-bounds global-memory read
that has already occurred.

The same issue also affects the corresponding neighbor accesses in srad_cuda_2.

Lenguaje dominante
C
Estrellas
56
Forks
41
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de JuliaParallel/rodinia

Todos los issues de JuliaParallel/rodinia

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.