Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: CI

on:
push:
branches: [ main, master ]
pull_request:

jobs:
rust:
name: Lint and Test (stable, ${{ matrix.features }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
features:
- ""
- complex
- stream
- complex,stream
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt

- name: Cache cargo
uses: Swatinem/rust-cache@v2

- name: Format check
run: cargo fmt --all -- --check

- name: Clippy (warnings as errors)
run: |
if [ -n "${{ matrix.features }}" ]; then
cargo clippy --all-targets --features "${{ matrix.features }}" -D warnings
else
cargo clippy --all-targets -D warnings
fi

- name: Test
run: |
if [ -n "${{ matrix.features }}" ]; then
cargo test --features "${{ matrix.features }}"
else
cargo test
fi

# Note: OpenCL-related tests are not run in CI by default.
# They require GPU drivers and an OpenCL ICD on the runner.
36 changes: 36 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Repository Guidelines

## Project Structure & Module Organization
- Source: `src/` with host and GPU backends: `src/host/`, `src/opencl/`, and core types in `src/array.rs`, `src/buffer.rs`, `src/ops/`.
- Library entry: `src/lib.rs` (crate type `rlib`/`cdylib`).
- OpenCL kernels: `src/opencl/programs/`.
- Tests: integration tests in `tests/*.rs` (e.g., `tests/construct.rs`).
- Packaging/build metadata: `Cargo.toml`, `Cargo.lock`; container setup in `Dockerfile`.

## Build, Test, and Development Commands
- Build (CPU/host only): `cargo build`.
- Enable features (e.g., OpenCL): `cargo build --features opencl` or all: `cargo build --features all`.
- Run tests: `cargo test` (host) or `cargo test --features opencl`.
- Docs: `cargo doc --no-deps` (add `--open` locally to view).
- Format and lint: `cargo fmt --all` and `cargo clippy --all-targets --all-features -D warnings`.

## Coding Style & Naming Conventions
- Rust 2021 edition; 4-space indentation; keep lines reasonably short.
- Modules/files: `snake_case` (e.g., `array.rs`); types/traits: `PascalCase` (e.g., `ArrayBuf`); functions/fields: `snake_case`.
- Prefer explicit types and small, focused modules; keep unsafe blocks minimal and well-justified.
- Run `cargo fmt` and `cargo clippy` before pushing.

## Testing Guidelines
- Framework: Rust `#[test]` with `cargo test`; integration tests live in `tests/*.rs`.
- Name tests descriptively (e.g., `#[test] fn transpose_concat_validates_dims()`), assert both values and shapes.
- For GPU-specific logic, guard with feature flags and provide host fallbacks when possible.
- Keep tests deterministic and fast; seed randomness when used.

## Commit & Pull Request Guidelines
- Commits: short, imperative subject (e.g., "implement Array::concat"), reference issues when relevant (e.g., `(#28)`).
- PRs: include a clear description, motivation, feature flags used (`opencl`, `complex`, etc.), and test coverage notes; add benchmarks only if necessary.
- Required: passing `cargo test`, `cargo fmt`, and `cargo clippy` with no new warnings.

## Security & Configuration Tips
- OpenCL support is optional (`--features opencl`) and requires drivers/ICD on the host; verify with `clinfo`.
- The provided `Dockerfile` can build with GPU support; run with `docker run --gpus=all` when testing OpenCL.
6 changes: 3 additions & 3 deletions src/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{Buffer, Error, Number, Platform};
/// A type which allows accessing array data
pub trait Access<T: Number>: Send + Sync {
/// Read the data of this accessor as a [`BufferConverter`].
fn read(&self) -> Result<BufferConverter<T>, Error>;
fn read(&self) -> Result<BufferConverter<'_, T>, Error>;

/// Access a single value.
fn read_value(&self, offset: usize) -> Result<T, Error>;
Expand Down Expand Up @@ -125,7 +125,7 @@ where
T: Number,
B: BufferInstance<T>,
{
fn read(&self) -> Result<BufferConverter<T>, Error> {
fn read(&self) -> Result<BufferConverter<'_, T>, Error> {
Ok(self.buffer.read())
}

Expand Down Expand Up @@ -301,7 +301,7 @@ pub enum Accessor<'a, T: Number> {
}

impl<'a, T: Number> Access<T> for Accessor<'a, T> {
fn read(&self) -> Result<BufferConverter<T>, Error> {
fn read(&self) -> Result<BufferConverter<'_, T>, Error> {
match self {
Self::Buffer(buf) => Ok(buf.read()),
Self::Op(op) => op.enqueue().map(BufferConverter::from),
Expand Down
Loading
Loading