Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datadeps: Add at-stencil helper #564

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

datadeps: Add at-stencil helper #564

wants to merge 9 commits into from

Conversation

jpsamaroo
Copy link
Member

@jpsamaroo jpsamaroo commented Aug 9, 2024

Adds an @stencil macro (and an @neighbors helper) for specifying stencil-like operations (such as convolutions) over one or more DArrays, which operate in parallel via Datadeps. For example, Conway's Game of Life can be specified as:

# Allocate game tiles and double-buffer
tiles = zeros(Blocks(N, N), Bool, N*nt, N*nt)
outputs = zeros(Blocks(N, N), Bool, N*nt, N*nt)

# Create a glider
tiles[13, 14] = 1
tiles[14, 14] = 1
tiles[15, 14] = 1
tiles[15, 15] = 1
tiles[14, 16] = 1

import Dagger: @stencil, Wrap

# Run Game of Life for one iteration
Dagger.spawn_datadeps() do
    @stencil begin
        outputs[idx] = begin
            nhood = @neighbors(tiles[idx], 1, Wrap())
            neighs = sum(nhood) - tiles[idx]
            if tiles[idx] && neighs < 2
                0
            elseif tiles[idx] && neighs > 3
                0
            elseif !tiles[idx] && neighs == 3
                1
            else
                tiles[idx]
            end
        end
        tiles[idx] = outputs[idx]
    end
end

Todo:

  • Add support for neighborhoods greater than 1
  • Fix neighborhood distances which reach the boundary
  • Add support for non-wrapping behavior (pad zero/custom element) (consider using Wrap() or Pad(0) syntax)
  • Remove requirement on idx=tiles syntax - just infer from write var of each expression
  • Add and validate GPU support
  • Consider renaming? This could become more general than stencils I like the current name
  • Automatically double-buffer read+written var
  • Add Game of Life and convolution examples
  • Add intro docs
  • Add tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant