#!/usr/bin/env bash
set -e

POWER_LIMIT_FILE="/etc/gpu-power-limit.conf"

if [[ ! -f "$POWER_LIMIT_FILE" ]]; then
  echo "❌ Не найден $POWER_LIMIT_FILE"
  exit 1
fi

POWER_LIMIT=$(cat "$POWER_LIMIT_FILE")

echo "▶ Enabling persistence mode"
nvidia-smi -pm 1

echo "▶ Setting power limit to ${POWER_LIMIT}W"
nvidia-smi -pl "$POWER_LIMIT"

echo "✅ GPU power configured"
