Skip to content
Open
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
28 changes: 28 additions & 0 deletions aios-layer/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
push:
paths:
- "aios-layer/**"
pull_request:
paths:
- "aios-layer/**"

jobs:
build-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: aios-layer
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- run: go mod download
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The CI workflow can be optimized by caching Go modules to speed up subsequent builds. Consider adding a caching step for ~/go/pkg/mod and the Go build cache before the go mod download step. You can use actions/cache for this.

- run: make build
- run: ./scripts/run_checks.sh
- uses: actions/upload-artifact@v4
with:
name: aios-layer-reports
path: aios-layer/reports
2 changes: 2 additions & 0 deletions aios-layer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin
/reports
20 changes: 20 additions & 0 deletions aios-layer/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Contributing

Thanks for contributing to AIOS Layer!

## Development setup

```bash
make build
make test
```

## Code style

- Go fmt (`gofmt`) required.
- Keep security-sensitive changes documented in `SECURITY.md`.

## Pull requests

- Include tests for new behavior.
- Update docs if user-facing changes are introduced.
21 changes: 21 additions & 0 deletions aios-layer/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions aios-layer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
SHELL := /usr/bin/env bash

.PHONY: build test bench run

build:
go build -o bin/aios-agent ./agent
go build -o bin/aiosctl ./cli
Comment on lines +5 to +7
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The build target attempts to write binaries to the bin/ directory, but it doesn't ensure this directory exists first. If the bin/ directory is missing, the go build command will fail.

build:
	mkdir -p bin
	go build -o bin/aios-agent ./agent
	go build -o bin/aiosctl ./cli


test:
go test -count=2 ./agent/... ./cli/...

bench:
mkdir -p reports
go test ./agent/... -run ^$ -bench . -benchmem -count=2 | tee reports/bench.log

run:
./bin/aios-agent -config config/aios.yaml
69 changes: 69 additions & 0 deletions aios-layer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# AIOS Layer (MVP)

AIOS Layer is a reproducible, secure-by-default AI/GPU “OS-style layer” that runs on top of an existing host OS. It provides a minimal host agent, GPU-aware scheduling, runtime launch hooks, and a CLI + optional UI for inference workflows.

## 10-minute Quickstart (Ubuntu 24.04 + NVIDIA)

1) **Install prerequisites**

```bash
sudo apt-get update
sudo apt-get install -y docker.io docker-compose-plugin
# NVIDIA drivers + container toolkit (see docs below)
```

2) **Build + run**

```bash
cd aios-layer
make build
./scripts/run_demo.sh
```

3) **Request a lease + run inference**

```bash
./bin/aiosctl lease --agent http://127.0.0.1:8080 --user demo --duration 300
./bin/aiosctl infer --endpoint http://127.0.0.1:8000/v1/chat/completions --prompt "Hello from AIOS"
```

4) **Open the UI**

```bash
python3 -m http.server 9000 -d ui
# visit http://127.0.0.1:9000/index.html
```

## Architecture Overview

- **Control plane**: `aios-agent` manages GPU discovery, scheduling, policy enforcement, and runtime launch.
- **Data plane**: model servers run in containers (vLLM in the MVP).
- **Interface**: `aiosctl` CLI and a static UI.

See `docs/architecture.md` for diagrams and rationale.

## NVIDIA GPU Integration (MVP)

- Driver + `nvidia-container-toolkit` required for GPU containers.
- GPU discovery via `nvidia-smi` (NVML alternative in v1).
- Scheduler uses exclusive GPU leases (time-based).
- CPU-only fallback is enabled when no GPU is detected.

## Security

- Minimal privileges for the agent and containers.
- Example seccomp + AppArmor profiles in `deploy/security`.
- No telemetry; metrics are local-only.

## Tests

```bash
make test
./scripts/run_checks.sh
```

Test and benchmark logs are written to `reports/` when using `./scripts/run_checks.sh`.

## License

MIT
15 changes: 15 additions & 0 deletions aios-layer/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Security Policy

## Reporting

Please report security issues by opening a private security advisory in the repository.

## Supported versions

Only the latest release is supported.

## Hardening

- Run `aios-agent` as a non-root user.
- Use AppArmor and seccomp profiles in `deploy/security`.
- Avoid granting containers additional capabilities.
56 changes: 56 additions & 0 deletions aios-layer/agent/internal/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package config

import (
"os"

"gopkg.in/yaml.v3"
)

type Config struct {
Server ServerConfig `yaml:"server"`
Policy PolicyConfig `yaml:"policy"`
Scheduler SchedulerConfig `yaml:"scheduler"`
Runtime RuntimeConfig `yaml:"runtime"`
Model ModelConfig `yaml:"model"`
Metrics MetricsConfig `yaml:"metrics"`
}

type ServerConfig struct {
ListenAddress string `yaml:"listen_address"`
}

type PolicyConfig struct {
MaxGPUsPerUser int `yaml:"max_gpus_per_user"`
MaxDurationSec int `yaml:"max_duration_sec"`
}

type SchedulerConfig struct {
LeaseTTLSeconds int `yaml:"lease_ttl_seconds"`
}

type RuntimeConfig struct {
DockerSocket string `yaml:"docker_socket"`
ModelImage string `yaml:"model_image"`
ModelPort int `yaml:"model_port"`
EnableLaunch bool `yaml:"enable_launch"`
}

type ModelConfig struct {
Endpoint string `yaml:"endpoint"`
}

type MetricsConfig struct {
Enabled bool `yaml:"enabled"`
}

func Load(path string) (Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return Config{}, err
}
var cfg Config
if err := yaml.Unmarshal(data, &cfg); err != nil {
return Config{}, err
}
return cfg, nil
}
54 changes: 54 additions & 0 deletions aios-layer/agent/internal/gpu/discovery.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package gpu

import (
"bufio"
"bytes"
"errors"
"os/exec"
"strconv"
"strings"
)

type GPU struct {
Index int `json:"index"`
Name string `json:"name"`
MemoryTotal int `json:"memory_total_mb"`
}

func Discover() ([]GPU, error) {
cmd := exec.Command("nvidia-smi", "--query-gpu=index,name,memory.total", "--format=csv,noheader,nounits")
output, err := cmd.Output()
if err != nil {
return nil, errors.New("nvidia-smi not available")
}
Comment on lines +21 to +23
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error returned when nvidia-smi is not found loses the original error context. Wrapping the error provides more detailed information for debugging, such as why the command failed to run (e.g., not in PATH).

		return nil, fmt.Errorf("nvidia-smi not available: %w", err)

return parseCSV(output)
}

func parseCSV(data []byte) ([]GPU, error) {
var gpus []GPU
scanner := bufio.NewScanner(bytes.NewReader(data))
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if line == "" {
continue
}
parts := strings.Split(line, ",")
if len(parts) < 3 {
continue
}
index, err := strconv.Atoi(strings.TrimSpace(parts[0]))
if err != nil {
continue
}
name := strings.TrimSpace(parts[1])
mem, err := strconv.Atoi(strings.TrimSpace(parts[2]))
if err != nil {
continue
}
Comment on lines +39 to +47
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The parseCSV function silently ignores parsing errors for GPU index and memory, which can lead to GPUs being missed without any notification. It's better to log these errors to aid in debugging potential issues with nvidia-smi output format changes. You will need to import the log package.

		index, err := strconv.Atoi(strings.TrimSpace(parts[0]))
		if err != nil {
			log.Printf("failed to parse GPU index from line '%s': %v", line, err)
			continue
		}
		name := strings.TrimSpace(parts[1])
		mem, err := strconv.Atoi(strings.TrimSpace(parts[2]))
		if err != nil {
			log.Printf("failed to parse GPU memory from line '%s': %v", line, err)
			continue
		}

gpus = append(gpus, GPU{Index: index, Name: name, MemoryTotal: mem})
}
if err := scanner.Err(); err != nil {
return nil, err
}
return gpus, nil
}
21 changes: 21 additions & 0 deletions aios-layer/agent/internal/policy/policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package policy

import "errors"

type Policy struct {
MaxGPUsPerUser int
MaxDurationSec int
}

func (p Policy) ValidateRequest(existingLeases int, requestedDuration int) error {
if p.MaxGPUsPerUser > 0 && existingLeases >= p.MaxGPUsPerUser {
return errors.New("gpu quota exceeded")
}
if p.MaxDurationSec > 0 && requestedDuration > p.MaxDurationSec {
return errors.New("requested duration exceeds policy")
}
if requestedDuration <= 0 {
return errors.New("invalid duration")
}
return nil
}
Comment on lines +10 to +21
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ValidateRequest function returns errors created with errors.New(). It's a better practice to define these as exported error variables. This allows callers to use errors.Is() to check for specific error types and handle them programmatically.

Suggested change
func (p Policy) ValidateRequest(existingLeases int, requestedDuration int) error {
if p.MaxGPUsPerUser > 0 && existingLeases >= p.MaxGPUsPerUser {
return errors.New("gpu quota exceeded")
}
if p.MaxDurationSec > 0 && requestedDuration > p.MaxDurationSec {
return errors.New("requested duration exceeds policy")
}
if requestedDuration <= 0 {
return errors.New("invalid duration")
}
return nil
}
var (
ErrQuotaExceeded = errors.New("gpu quota exceeded")
ErrDurationExceedsPolicy = errors.New("requested duration exceeds policy")
ErrInvalidDuration = errors.New("invalid duration")
)
func (p Policy) ValidateRequest(existingLeases int, requestedDuration int) error {
if p.MaxGPUsPerUser > 0 && existingLeases >= p.MaxGPUsPerUser {
return ErrQuotaExceeded
}
if p.MaxDurationSec > 0 && requestedDuration > p.MaxDurationSec {
return ErrDurationExceedsPolicy
}
if requestedDuration <= 0 {
return ErrInvalidDuration
}
return nil
}

24 changes: 24 additions & 0 deletions aios-layer/agent/internal/runtime/docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package runtime

import (
"fmt"
"os/exec"
)

type DockerLauncher struct {
Socket string
Image string
ModelPort int
}

func (d DockerLauncher) Launch(gpuIndex int) error {
args := []string{
"-H", d.Socket,
"run", "--rm", "-d",
"--gpus", fmt.Sprintf("device=%d", gpuIndex),
"-p", fmt.Sprintf("%d:%d", d.ModelPort, d.ModelPort),
d.Image,
}
cmd := exec.Command("docker", args...)
return cmd.Run()
}
Loading