-
Notifications
You must be signed in to change notification settings - Fork 33
Introducing AGENTS.md #2233
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
base: master
Are you sure you want to change the base?
Introducing AGENTS.md #2233
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| applyTo: | ||
| - "dpctl/**/*.pyx" | ||
| - "dpctl/**/*.pxd" | ||
| - "dpctl/**/*.pxi" | ||
| --- | ||
|
|
||
| # Cython Instructions | ||
|
|
||
| See `dpctl/AGENTS.md` for full conventions. | ||
|
|
||
| ## Required Directives (after license) | ||
| ```cython | ||
| # distutils: language = c++ | ||
| # cython: language_level=3 | ||
| # cython: linetrace=True | ||
| ``` | ||
|
|
||
| ## Key Rules | ||
| - `cimport` for C-level, `import` for Python-level | ||
| - Store C refs as `_*_ref`, clean up in `__dealloc__` with NULL check | ||
| - Use `with nogil:` for blocking C operations |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
| applyTo: | ||
| - "**/*.py" | ||
| - "**/*.pyx" | ||
| - "**/*.pxd" | ||
| - "**/*.cpp" | ||
| - "**/*.hpp" | ||
| - "**/*.h" | ||
| --- | ||
|
|
||
| # DPCTL General Instructions | ||
|
|
||
| See `AGENTS.md` at repository root for project overview and architecture. | ||
| Each major directory has its own `AGENTS.md` with specific conventions. | ||
|
|
||
| ## Key References | ||
|
|
||
| - **Code style:** `.pre-commit-config.yaml`, `.clang-format`, `.flake8` | ||
| - **License:** Apache 2.0 with Intel copyright - match existing file headers | ||
|
|
||
| ## Critical Rules | ||
|
|
||
| 1. **Device compatibility:** Not all devices support fp64/fp16 - never assume availability | ||
| 2. **Queue consistency:** Arrays in same operation must share compatible queues | ||
| 3. **Resource cleanup:** Clean up C resources in `__dealloc__` with NULL check | ||
| 4. **NULL checks:** Always check C API returns before use | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --- | ||
| applyTo: | ||
| - "libsyclinterface/**/*.h" | ||
| - "libsyclinterface/**/*.hpp" | ||
| - "libsyclinterface/**/*.cpp" | ||
| --- | ||
|
|
||
| # C API Instructions | ||
|
|
||
| See `libsyclinterface/AGENTS.md` for conventions. | ||
|
|
||
| ## Naming | ||
| `DPCTL<ClassName>_<MethodName>` (e.g., `DPCTLDevice_Create`) | ||
|
|
||
| ## Ownership annotations (see `include/syclinterface/Support/MemOwnershipAttrs.h`) | ||
| - `__dpctl_give` - caller must free | ||
| - `__dpctl_take` - function takes ownership | ||
| - `__dpctl_keep` - function only observes | ||
|
|
||
| ## Key Rules | ||
| - Annotate all parameters and returns | ||
| - Return NULL on failure | ||
| - Use `DPCTL_API` for exports |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- | ||
| applyTo: | ||
| - "dpctl/memory/**" | ||
| - "**/test_sycl_usm*.py" | ||
| --- | ||
|
|
||
| # USM Memory Instructions | ||
|
|
||
| See `dpctl/memory/AGENTS.md` for details. | ||
|
|
||
| ## USM Types | ||
| - `MemoryUSMDevice` - device-only (fastest) | ||
| - `MemoryUSMShared` - host and device accessible | ||
| - `MemoryUSMHost` - host memory, device accessible | ||
|
|
||
| ## Lifetime Rules | ||
| 1. Memory is queue-bound | ||
| 2. Keep memory alive until operations complete | ||
| 3. Views extend base memory lifetime |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --- | ||
| applyTo: | ||
| - "dpctl/tests/**/*.py" | ||
| - "**/test_*.py" | ||
| --- | ||
|
|
||
| # Testing Instructions | ||
|
|
||
| See `dpctl/tests/AGENTS.md` for patterns. | ||
|
|
||
| ## Essential helpers (from `helper/_helper.py`) | ||
| ```python | ||
| get_queue_or_skip() # Create queue or skip | ||
| skip_if_dtype_not_supported() # Skip if device lacks dtype | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as below, dtypes not a concern right now without tensor |
||
| ``` | ||
|
|
||
| ## Dtype/USM lists | ||
| Import from `elementwise/utils.py` - do not hardcode. | ||
|
|
||
| ## Coverage | ||
| - All dtypes from `_all_dtypes` | ||
| - All USM types: device, shared, host | ||
| - Edge cases: empty, scalar, broadcast | ||
|
Comment on lines
+17
to
+23
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also not relevant without tensor |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # AGENTS.md - AI Agent Guide for DPCTL | ||
|
|
||
| ## Purpose | ||
|
|
||
| This file is the top-level entry point for AI agents working in `IntelPython/dpctl`. | ||
| Use it to orient quickly, then follow directory-level `AGENTS.md` files for implementation details and local conventions. | ||
|
|
||
| ## Repository Scope | ||
|
|
||
| DPCTL provides Python bindings for SYCL runtime objects and supporting infrastructure. | ||
|
|
||
| High-level stack: | ||
|
|
||
| ``` | ||
| Python API -> Cython Bindings -> C API (libsyclinterface) -> SYCL Runtime | ||
| ``` | ||
|
|
||
| ## How to Work in This Repo | ||
|
|
||
| 1. Identify the directory you are changing. | ||
| 2. Read the nearest `AGENTS.md` for that directory. | ||
| 3. Keep changes local and minimal; avoid unrelated refactors. | ||
| 4. Validate behavior with targeted tests before broad test runs. | ||
|
|
||
| ## Directory Guide | ||
|
|
||
| | Directory | Guide | Notes | | ||
| |-----------|-------|-------| | ||
| | `dpctl/` | `dpctl/AGENTS.md` | Core SYCL Python bindings and Cython patterns | | ||
| | `dpctl/memory/` | `dpctl/memory/AGENTS.md` | USM memory model and ownership rules | | ||
| | `dpctl/program/` | `dpctl/program/AGENTS.md` | Program/kernel compilation APIs | | ||
| | `dpctl/utils/` | `dpctl/utils/AGENTS.md` | Queue and utility validation helpers | | ||
| | `dpctl/tests/` | `dpctl/tests/AGENTS.md` | Test conventions and coverage expectations | | ||
| | `libsyclinterface/` | `libsyclinterface/AGENTS.md` | C API contracts and ABI-safe patterns | | ||
|
|
||
| ## Global Constraints | ||
|
|
||
| - Match existing Apache 2.0 + Intel header style for source files. | ||
| - Respect style tooling from `.pre-commit-config.yaml`, `.clang-format`, and `.flake8`. | ||
| - Do not assume all devices support fp64/fp16. | ||
napetrov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - Preserve queue/device compatibility checks and explicit error paths. | ||
| - Keep memory/resource cleanup explicit and safe. | ||
|
|
||
| ## Notes on GitHub Copilot Instructions | ||
|
|
||
| Files under `.github/instructions/*.instructions.md` are entry points for Copilot behavior. | ||
| They should stay concise and reference authoritative `AGENTS.md` files rather than duplicating full guidance. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # dpctl/ - Core SYCL Bindings | ||
|
|
||
| ## Purpose | ||
|
|
||
| Python/Cython wrappers for SYCL runtime objects: Device, Queue, Context, Event, Platform. | ||
|
|
||
| ## Key Files | ||
|
|
||
| | File | Purpose | | ||
| |------|---------| | ||
| | `_sycl_device.pyx` | `SyclDevice` wrapping `sycl::device` | | ||
| | `_sycl_queue.pyx` | `SyclQueue` wrapping `sycl::queue` | | ||
| | `_sycl_context.pyx` | `SyclContext` wrapping `sycl::context` | | ||
| | `_sycl_event.pyx` | `SyclEvent` wrapping `sycl::event` | | ||
| | `_sycl_platform.pyx` | `SyclPlatform` wrapping `sycl::platform` | | ||
| | `_sycl_device_factory.pyx` | Device enumeration and selection | | ||
| | `_sycl_queue_manager.pyx` | Queue management utilities | | ||
| | `_backend.pxd` | C API declarations from libsyclinterface | | ||
| | `enum_types.py` | Python enums for SYCL types | | ||
|
|
||
| ## Cython Conventions | ||
|
|
||
| ### Required Directives (after license header) | ||
| ```cython | ||
| # distutils: language = c++ | ||
| # cython: language_level=3 | ||
| # cython: linetrace=True | ||
| ``` | ||
|
|
||
| ### Extension Type Pattern | ||
| ```cython | ||
| cdef class SyclDevice: | ||
| cdef DPCTLSyclDeviceRef _device_ref # C reference | ||
|
|
||
| def __dealloc__(self): | ||
| if self._device_ref is not NULL: | ||
| DPCTLDevice_Delete(self._device_ref) | ||
|
|
||
| cdef DPCTLSyclDeviceRef get_device_ref(self): | ||
| return self._device_ref | ||
| ``` | ||
|
|
||
| ### Key Rules | ||
| - Store C references as `_*_ref` attributes | ||
| - Always clean up in `__dealloc__` with NULL check | ||
| - Use `with nogil:` for blocking C calls | ||
| - Check NULL before using C API returns | ||
|
|
||
| ### Exceptions | ||
| - `SyclDeviceCreationError` | ||
| - `SyclQueueCreationError` | ||
| - `SyclContextCreationError` | ||
|
|
||
| ## cimport vs import | ||
|
|
||
| ```cython | ||
| # cimport - C-level declarations (compile-time) | ||
| from ._backend cimport DPCTLSyclDeviceRef, DPCTLDevice_Create | ||
|
|
||
| # import - Python-level (runtime) | ||
| from . import _device_selection | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # dpctl/memory/ - USM Memory Management | ||
|
|
||
| ## Purpose | ||
|
|
||
| Python classes for SYCL Unified Shared Memory (USM) allocation. | ||
|
|
||
| ## USM Types | ||
|
|
||
| | Class | USM Type | Description | | ||
| |-------|----------|-------------| | ||
| | `MemoryUSMDevice` | Device | Device-only, fastest access | | ||
| | `MemoryUSMShared` | Shared | Host and device accessible | | ||
| | `MemoryUSMHost` | Host | Host memory, device accessible | | ||
|
|
||
| ## __sycl_usm_array_interface__ | ||
|
|
||
| All memory classes implement this protocol: | ||
| ```python | ||
| { | ||
| "data": (ptr, readonly_flag), | ||
| "shape": (nbytes,), | ||
| "strides": None, | ||
| "typestr": "|u1", | ||
| "version": 1, | ||
| "syclobj": queue | ||
| } | ||
| ``` | ||
|
|
||
| ## Memory Lifetime Rules | ||
|
|
||
| 1. **Queue-bound:** Memory tied to specific queue/context | ||
| 2. **Outlive operations:** Keep memory alive until operations complete | ||
| 3. **Views extend lifetime:** Views keep base memory alive | ||
|
|
||
| ## Key Files | ||
|
|
||
| | File | Purpose | | ||
| |------|---------| | ||
| | `_memory.pyx` | Memory class implementations | | ||
| | `_memory.pxd` | Cython declarations | | ||
| | `__init__.py` | Public API exports | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # dpctl/program/ - SYCL Kernel Compilation | ||
|
|
||
| ## Purpose | ||
|
|
||
| Compile and manage SYCL kernels from OpenCL C or SPIR-V source. | ||
|
|
||
| ## Key Files | ||
|
|
||
| | File | Purpose | | ||
| |------|---------| | ||
| | `_program.pyx` | `SyclProgram`, `SyclKernel` extension types | | ||
| | `_program.pxd` | Cython declarations | | ||
| | `__init__.py` | Public API exports | | ||
|
|
||
| ## Classes | ||
|
|
||
| - **`SyclProgram`** - Compiled SYCL program containing one or more kernels | ||
| - **`SyclKernel`** - Individual kernel extracted from a program | ||
|
|
||
| ## Usage Pattern | ||
|
|
||
| ```python | ||
| from dpctl.program import create_program_from_source | ||
|
|
||
| source = """ | ||
| __kernel void add(__global float* a, __global float* b, __global float* c) { | ||
| int i = get_global_id(0); | ||
| c[i] = a[i] + b[i]; | ||
| } | ||
| """ | ||
|
|
||
| program = create_program_from_source(queue, source) | ||
| kernel = program.get_sycl_kernel("add") | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - Programs are context-bound | ||
| - Follows same Cython patterns as core dpctl (see `../AGENTS.md`) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # dpctl/tests/ - Test Suite | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in general, this should be rewritten without tensor: the focus of the test suite with tensor being removed is on functionality of Python-exposed SYCL objects |
||
|
|
||
| ## Purpose | ||
|
|
||
| pytest-based test suite for dpctl functionality. | ||
|
|
||
| ## Key Files | ||
|
|
||
| | File | Purpose | | ||
| |------|---------| | ||
| | `conftest.py` | Fixtures and pytest configuration | | ||
| | `helper/_helper.py` | `get_queue_or_skip()`, `skip_if_dtype_not_supported()` | | ||
| | `elementwise/utils.py` | Dtype and USM type lists for parametrization | | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| ## Essential Helpers | ||
|
|
||
| From `helper/_helper.py`: | ||
| ```python | ||
| get_queue_or_skip() # Create queue or skip test | ||
| skip_if_dtype_not_supported() # Skip if device lacks dtype (fp64/fp16) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. without tensor, this will also not be relevant |
||
| ``` | ||
|
|
||
| ## Dtype/USM Lists | ||
|
|
||
| **Do not hardcode** - import from `elementwise/utils.py`: | ||
| ```python | ||
| from .utils import _all_dtypes, _usm_types, _no_complex_dtypes | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also won't exist without tensor |
||
| ``` | ||
|
|
||
| ## Test Pattern | ||
|
|
||
| ```python | ||
| @pytest.mark.parametrize("dtype", _all_dtypes) | ||
| def test_operation(dtype): | ||
| q = get_queue_or_skip() | ||
| skip_if_dtype_not_supported(dtype, q) | ||
|
|
||
| x = dpt.ones(100, dtype=dtype, sycl_queue=q) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uses tensor here, too |
||
| result = dpt.operation(x) | ||
| # ... assertions | ||
| ``` | ||
|
|
||
| ## Coverage Requirements | ||
|
|
||
| - All supported dtypes (see `elementwise/utils.py`) | ||
| - All USM types: device, shared, host | ||
| - Memory orders: C, F where applicable | ||
| - Edge cases: empty arrays, 0-d arrays (scalars), broadcasting | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # dpctl/utils/ - Utility Functions | ||
|
|
||
| ## Purpose | ||
|
|
||
| Helper utilities for device queries, execution context management, and ordering. | ||
|
|
||
| ## Key Files | ||
|
|
||
| | File | Purpose | | ||
| |------|---------| | ||
| | `_compute_follows_data.pyx` | `get_execution_queue()` for queue compatibility | | ||
| | `_order_manager.py` | `OrderManager` for memory layout handling | | ||
| | `_intel_device_info.py` | Intel-specific device information | | ||
| | `_onetrace_context.py` | Tracing/profiling context manager | | ||
|
|
||
| ## Key Functions | ||
|
|
||
| ### get_execution_queue() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed in tensor migration |
||
| Validates queue compatibility between arrays: | ||
| ```python | ||
| from dpctl.utils import get_execution_queue | ||
|
|
||
| exec_q = get_execution_queue([x.sycl_queue, y.sycl_queue]) | ||
| if exec_q is None: | ||
| raise ExecutionPlacementError("Incompatible queues") | ||
| ``` | ||
|
|
||
| ### ExecutionPlacementError | ||
| Exception raised when arrays are on incompatible queues. | ||
|
Comment on lines
+28
to
+29
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed in tensor migration |
||
|
|
||
| ## Notes | ||
|
|
||
| - `get_execution_queue()` is critical for all tensor operations | ||
| - See usage examples in `dpctl/tensor/` modules | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no arrays without
tensor