Skip to content

Commit 671eb17

Browse files
Add copilot instructions
Apparently this file speeds up process of AI contributions to this repository. It was fully generated by copilot.
1 parent 44f1c63 commit 671eb17

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

.github/copilot-instructions.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# UMF (Unified Memory Framework) - AI Coding Guide
2+
3+
## Project Architecture
4+
5+
UMF is a C library for constructing memory allocators and pools, built around a two-layer architecture:
6+
7+
- **Memory Providers** (`src/provider/`): Handle coarse-grained OS-level memory allocation (mmap, CUDA, Level Zero, etc.)
8+
- **Memory Pools** (`src/pool/`): Handle fine-grained allocation using providers as backing store (jemalloc, scalable, disjoint)
9+
10+
Key architectural patterns:
11+
- Provider/pool separation enables mixing any provider with any pool allocator
12+
- Operations structures (`*_ops_t`) define plugin interfaces for extensibility
13+
- Handle-based API (`*_handle_t`) abstracts implementation details
14+
- Result codes (`umf_result_t`) for consistent error handling
15+
16+
## Development Workflows
17+
18+
### Build System
19+
```bash
20+
# Standard build
21+
cmake -B build -DCMAKE_BUILD_TYPE=Release
22+
cmake --build build -j $(nproc)
23+
24+
# Enable all features for development
25+
cmake -B build -DCMAKE_BUILD_TYPE=Debug \
26+
-DUMF_BUILD_TESTS=ON -DUMF_BUILD_GPU_TESTS=ON \
27+
-DUMF_BUILD_EXAMPLES=ON -DUMF_DEVELOPER_MODE=ON
28+
```
29+
30+
### Version Management
31+
- Version determined by: 1) `git describe` (preferred), 2) `VERSION` file fallback, 3) "0.0.0" default
32+
- `set_version_variables()` in `cmake/helpers.cmake` handles version detection
33+
- For releases: create `VERSION` file with semver format (e.g., "1.0.3-dev")
34+
35+
### Code Formatting
36+
- **Always format code before committing**: `make format-apply`
37+
- Requires build with `-DUMF_FORMAT_CODE_STYLE=ON`
38+
- Uses clang-format-15.0, cmake-format-0.6, and black for Python
39+
40+
### Testing Patterns
41+
- Use `build_umf_test()` CMake function in `test/CMakeLists.txt`
42+
- GPU tests require `UMF_BUILD_GPU_TESTS=ON` and hardware/drivers
43+
- IPC tests use producer/consumer pattern with shell scripts
44+
- Platform-specific tests: `.c` files for portability, `.cpp` for C++ features
45+
46+
### CI/CD Structure
47+
- `pr_push.yml`: Main workflow calling reusable workflows
48+
- Separate workflows for different configurations: `reusable_gpu.yml`, `reusable_sanitizers.yml`
49+
- Provider-specific testing: Level Zero, CUDA runners with actual hardware
50+
51+
## Coding Conventions
52+
53+
### Naming Patterns
54+
- Public API: `umf*` prefix (e.g., `umfMemoryProviderCreate`)
55+
- Internal functions: `snake_case` without prefix
56+
- Structures: `*_t` suffix for types, `*_handle_t` for opaque handles
57+
- Constants: `UMF_*` uppercase with underscores
58+
59+
### Memory Management Patterns
60+
- Always pair create/destroy functions (e.g., `umfMemoryProviderCreate`/`umfMemoryProviderDestroy`)
61+
- Use `umf_result_t` return codes, never throw exceptions
62+
- Provider params have separate create/destroy lifecycle
63+
- Thread-local storage (`__TLS`) for error state in providers
64+
65+
### Provider Implementation Pattern
66+
```c
67+
// Standard provider structure
68+
typedef struct my_provider_t {
69+
// Provider-specific state
70+
} my_provider_t;
71+
72+
static umf_result_t my_initialize(const void *params, void **provider);
73+
static umf_result_t my_finalize(void *provider);
74+
static umf_result_t my_alloc(void *provider, size_t size, size_t alignment, void **ptr);
75+
static umf_result_t my_free(void *provider, void *ptr, size_t size);
76+
77+
static const umf_memory_provider_ops_t MY_PROVIDER_OPS = {
78+
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
79+
.initialize = my_initialize,
80+
.finalize = my_finalize,
81+
.alloc = my_alloc,
82+
.free = my_free,
83+
// ... other required ops
84+
};
85+
```
86+
87+
## Key Files and Patterns
88+
89+
### Core APIs
90+
- `include/umf.h`: Main header, include this for basic usage
91+
- `include/umf/memory_provider_ops.h`: Provider plugin interface
92+
- `include/umf/memory_pool_ops.h`: Pool plugin interface
93+
94+
### Common Utilities
95+
- `src/utils/`: Logging (`utils_log.h`), concurrency (`utils_concurrency.h`), assertions
96+
- `src/critnib/`: Concurrent radix tree for address tracking
97+
- `src/base_alloc/`: Base allocation utilities
98+
99+
### Platform Abstractions
100+
- `libumf_linux.c`/`libumf_windows.c`: OS-specific implementations
101+
- `topology.c`: HWLOC integration for NUMA topology discovery
102+
- Provider files handle platform-specific allocation (CUDA, Level Zero, OS memory)
103+
104+
## Integration Points
105+
106+
### NUMA Support
107+
- Uses HWLOC for topology discovery (`topology.c`, `umf_hwloc.h`)
108+
- NUMA policies in `mempolicy.c`: bind, interleave, split modes
109+
- Memory spaces (`memspace.c`) and targets (`memtarget.c`) for NUMA abstraction
110+
111+
### GPU Integration
112+
- Level Zero provider: `provider_level_zero.c` for Intel GPUs
113+
- CUDA provider: `provider_cuda.c` for NVIDIA GPUs
114+
- Examples in `examples/level_zero_shared_memory/` and `examples/cuda_shared_memory/`
115+
116+
### IPC (Inter-Process Communication)
117+
- Linux-specific implementation using file descriptor passing
118+
- Requires `PTRACE_MODE_ATTACH_REALCREDS` permission
119+
- Uses `memfd_create()` or `memfd_secret()` for anonymous shared memory
120+
121+
When implementing new providers or pools, follow the existing patterns in `src/provider/provider_os_memory.c` and `src/pool/pool_scalable.c` as reference implementations.

0 commit comments

Comments
 (0)