How ashishgy/footdetec works
Project Type and Purpose
• This is an open-source Python/C++ mixed library (“ai3”) that extends PyTorch to provide fine-grain, user-selectable DNN algorithm implementations.
• Users call ai3.swap_operation or ai3.convert at the Python level to swap or convert PyTorch layers to high-performance implementations (cuDNN, SYCL, plain C++, etc.).
File Structure Analysis
• Top-level directories:
• src/ai3: Python package + C++ extension source (csrc) and custom hook headers.
• bench: Python benchmarking scripts and result data.
• example: Usage scripts demonstrating swap_operation, custom operators, training.
• model_zoo: Reference models for testing and demonstration.
• test: Unit, ops, serialization tests validating correctness.
• cmake: Custom CMake modules to find SYCL, configure builds.
• pyproject.toml, CMakeLists.txt: Build and packaging configuration.
• Patterns:
• Layered structure: Python API → C++ extension modules per operator → underlying acceleration backends.
• Plugin/custom directory for user-provided algorithms.
• Benchmarking and example harnesses are decoupled from core library.
README Insights
• Two main user entry points: swap_operation (in-place swap) and convert (full-model conversion).
• Supported operations (conv2d, linear, pooling, ReLU, flatten) with multiple algorithms and backend compatibility tables.
• Emphasis on zero overhead and fine-grain control.
Components
a. Main Components
• User Applications: PyTorch models, example scripts, custom operators.
• Python API Layer: src/ai3/__init__.py, layers.py, tensor.py, swap_torch.py.
• Dispatcher/Selector: AlgorithmicSelector logic in Python that chooses which C++ kernel to call.
• C++ Extension Modules: src/ai3/csrc/* (conv2d, linear, pooling, relu, flatten).
• Acceleration Backends: cuDNN, SYCL, CUBLAS, MPS, Metal, or plain C++ direct implementations.
• Build System: CMake (custom.cmake, FindSYCL), Python packaging (pyproject.toml).
• Auxiliary Components: Bench scripts (bench/), examples (example/), tests (test/), documentation (docs/).
b. Relationships and Interactions
• User code imports aithree Python package ⇒ calls swap_operation/convert.
• Python API constructs an internal Model object, walks the PyTorch graph, and dispatches each op to the selected C++ kernel via PyBind11 or similar binding.
• At build time, CMake compiles the C++ sources (csrc) into shared libraries, linking to chosen backends (cuDNN, SYCL).
• Bench scripts invoke both PyTorch and ai3 implementations to gather performance data.
c. Architectural Patterns
• Layered modular design separating API, dispatch logic, and compute kernels.
• Strategy pattern in Python: pluggable algorithms per operation.
• Extension/plugin architecture: src/ai3/custom for user-provided kernels.
d. Key Technologies
• Python (user API, benchmarks, tests, examples).
• C++ (compute kernels in src/ai3/csrc).
• Build: CMake + custom modules, pyproject.toml for pip distribution.
• Backends: NVIDIA cuDNN/cuBLAS, SYCL, Metal, MPS, plain C++.