Skip to content

Commit cd038ff

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 cd038ff

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

.github/copilot-instructions.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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")
34+
35+
### Testing Patterns
36+
- Use `build_umf_test()` CMake function in `test/CMakeLists.txt`
37+
- GPU tests require `UMF_BUILD_GPU_TESTS=ON` and hardware/drivers
38+
- IPC tests use producer/consumer pattern with shell scripts
39+
- Platform-specific tests: `.c` files for portability, `.cpp` for C++ features
40+
41+
### CI/CD Structure
42+
- `pr_push.yml`: Main workflow calling reusable workflows
43+
- Separate workflows for different configurations: `reusable_gpu.yml`, `reusable_sanitizers.yml`
44+
- Provider-specific testing: Level Zero, CUDA runners with actual hardware
45+
46+
## Coding Conventions
47+
48+
### Naming Patterns
49+
- Public API: `umf*` prefix (e.g., `umfMemoryProviderCreate`)
50+
- Internal functions: `snake_case` without prefix
51+
- Structures: `*_t` suffix for types, `*_handle_t` for opaque handles
52+
- Constants: `UMF_*` uppercase with underscores
53+
54+
### Memory Management Patterns
55+
- Always pair create/destroy functions (e.g., `umfMemoryProviderCreate`/`umfMemoryProviderDestroy`)
56+
- Use `umf_result_t` return codes, never throw exceptions
57+
- Provider params have separate create/destroy lifecycle
58+
- Thread-local storage (`__TLS`) for error state in providers
59+
60+
### Provider Implementation Pattern
61+
```c
62+
// Standard provider structure
63+
typedef struct my_provider_t {
64+
// Provider-specific state
65+
} my_provider_t;
66+
67+
static umf_result_t my_initialize(const void *params, void **provider);
68+
static umf_result_t my_finalize(void *provider);
69+
static umf_result_t my_alloc(void *provider, size_t size, size_t alignment, void **ptr);
70+
static umf_result_t my_free(void *provider, void *ptr, size_t size);
71+
72+
static const umf_memory_provider_ops_t MY_PROVIDER_OPS = {
73+
.version = UMF_PROVIDER_OPS_VERSION_CURRENT,
74+
.initialize = my_initialize,
75+
.finalize = my_finalize,
76+
.alloc = my_alloc,
77+
.free = my_free,
78+
// ... other required ops
79+
};
80+
```
81+
82+
## Key Files and Patterns
83+
84+
### Core APIs
85+
- `include/umf.h`: Main header, include this for basic usage
86+
- `include/umf/memory_provider_ops.h`: Provider plugin interface
87+
- `include/umf/memory_pool_ops.h`: Pool plugin interface
88+
89+
### Common Utilities
90+
- `src/utils/`: Logging (`utils_log.h`), concurrency (`utils_concurrency.h`), assertions
91+
- `src/critnib/`: Concurrent radix tree for address tracking
92+
- `src/base_alloc/`: Base allocation utilities
93+
94+
### Platform Abstractions
95+
- `libumf_linux.c`/`libumf_windows.c`: OS-specific implementations
96+
- `topology.c`: HWLOC integration for NUMA topology discovery
97+
- Provider files handle platform-specific allocation (CUDA, Level Zero, OS memory)
98+
99+
## Integration Points
100+
101+
### NUMA Support
102+
- Uses HWLOC for topology discovery (`topology.c`, `umf_hwloc.h`)
103+
- NUMA policies in `mempolicy.c`: bind, interleave, split modes
104+
- Memory spaces (`memspace.c`) and targets (`memtarget.c`) for NUMA abstraction
105+
106+
### GPU Integration
107+
- Level Zero provider: `provider_level_zero.c` for Intel GPUs
108+
- CUDA provider: `provider_cuda.c` for NVIDIA GPUs
109+
- Examples in `examples/level_zero_shared_memory/` and `examples/cuda_shared_memory/`
110+
111+
### IPC (Inter-Process Communication)
112+
- Linux-specific implementation using file descriptor passing
113+
- Requires `PTRACE_MODE_ATTACH_REALCREDS` permission
114+
- Uses `memfd_create()` or `memfd_secret()` for anonymous shared memory
115+
116+
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)