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

Add GPU support for sparse matrix multiplication with events #56

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Routhleck
Copy link
Collaborator

@Routhleck Routhleck commented Jan 22, 2025

Summary by Sourcery

New Features:

  • Enable GPU support for sparse matrix-vector and sparse matrix-matrix multiplication with event handling.

Copy link
Contributor

sourcery-ai bot commented Jan 22, 2025

Reviewer's Guide by Sourcery

This pull request introduces GPU support for sparse matrix multiplication and vector multiplication operations using Pallas. It includes both forward and transposed operations, and it supports boolean, float, and float-as-event data types.

Sequence diagram for GPU-based CSR matrix-vector multiplication

sequenceDiagram
    participant Client
    participant event_csrmv_p
    participant GPU_Kernel
    participant Memory

    Client->>event_csrmv_p: Call with weights, indices, indptr, v
    alt GPU backend
        event_csrmv_p->>GPU_Kernel: Generate kernel with block_size
        GPU_Kernel->>Memory: Atomic operations on output vector
        loop For each block
            GPU_Kernel->>GPU_Kernel: Process rows in block
            GPU_Kernel->>Memory: Update results
        end
        Memory-->>Client: Return result vector
    end
Loading

Class diagram for CSR matrix operations

classDiagram
    class event_csrmv_p {
        +cpu_kernel_or_generator
        +gpu_kernel_or_generator
        +defjvp()
        +def_transpose_rule()
    }
    class event_csrmm_p {
        +cpu_kernel_or_generator
        +gpu_kernel_or_generator
        +def_batching_rule()
    }
    class Kernel {
        +block_size: int
        +shape: Shape
        +float_as_event: bool
        +weight_info: ShapeDtypeStruct
        +indices_info: ShapeDtypeStruct
        +spike_info: ShapeDtypeStruct
        +transpose: bool
    }
    event_csrmv_p ..> Kernel
    event_csrmm_p ..> Kernel
Loading

File-Level Changes

Change Details Files
Added GPU kernel generation for sparse matrix-vector multiplication.
  • Implemented event_csrmv_gpu_kernel_generator to generate Pallas kernels for GPU execution.
  • Added support for transposed and non-transposed matrix-vector multiplication.
  • Included handling for boolean, float, and float-as-event data types.
  • Added support for scalar and non-scalar weights.
  • Added block_size parameter to control the size of the blocks processed by the kernel.
  • Modified event_csrmv_p_call to use the GPU kernel when not on CPU.
brainstate/event/_csr.py
Added GPU kernel generation for sparse matrix-matrix multiplication.
  • Implemented event_csrmm_gpu_kernel_generator to generate Pallas kernels for GPU execution.
  • Added support for transposed and non-transposed matrix-matrix multiplication.
  • Included handling for boolean, float, and float-as-event data types.
  • Added support for scalar and non-scalar weights.
  • Added block_size parameter to control the size of the blocks processed by the kernel.
  • Modified event_csrmm_p_call to use the GPU kernel when not on CPU.
brainstate/event/_csr.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai bot changed the title @sourcery-ai Add GPU support for sparse matrix multiplication with events Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant