Skip to content

Offsetting kernel indices #384

Closed

Description

@glwagner

It'd be extremely useful to have a feature for offsetting the kernel index, either at launch time or setup time.

Not sure what the best design or interface would be. @simone-silvestri and I discussed possibly embellishing StaticSize:

struct StaticSize{S} <: _Size
function StaticSize{S}() where S
new{S::Tuple{Vararg{Int}}}()
end

Our work exclusively uses statically sized kernels so I think we'd prefer a way to specify the offsets statically; eg the size and offset are simultaneously determined.

But another possibility would be to accept offsets as a kwarg similar to how ndrange is accepted for DynamicSize?

Activity

  1. vchuravy commented on Apr 18, 2023

    @vchuravy
    Member

    I talked with Simone and I think expressing this as an Index projection similar to LinearIndicies and CartesianIndices is the right direction.

  2. b-fg commented on May 1, 2023

    @b-fg
    Contributor

    In WaterLily we could also benefit from this as we are currently passing index offsets manually too.

  3. added
    kernels
    on Oct 19, 2026
  4. maleadt commented on Oct 19, 2026

    @maleadt
    Member

    Implemented in #771 (KA 0.10): ndrange entries may be index ranges, given at launch or statically, and @index(Global, Cartesian)/@index(Global, NTuple) return the shifted indices.

    @kernel function k!(A)
        i, j = @index(Global, NTuple)
        A[i, j] = 1
    end
    k!(backend)(A; ndrange=(2:4, 3:5))       # at launch
    k!(backend, (2, 2), (2:4, 3:5))(A)       # statically
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kernels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions