name: operator_benchmark

on:
  push:
    tags:
      - ciflow/op-benchmark/*
  workflow_dispatch:
    inputs:
      test_mode:
        required: false
        type: string
        default: 'short'
        description: tag filter for operator benchmarks, options from long, short, all
  schedule:
    # Run at 07:00 UTC every Sunday
    - cron: 0 7 * * 0
  pull_request:
    paths:
      - benchmarks/operator_benchmark/**
      - .github/workflows/operator_benchmark.yml

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}
  cancel-in-progress: true

permissions:
  id-token: write
  contents: read

jobs:
  opbenchmark-build:
    if: github.repository_owner == 'pytorch'
    name: opbenchmark-build
    uses: ./.github/workflows/_linux-build.yml
    with:
      build-environment: linux-jammy-py3.10-gcc11-build
      docker-image-name: ci-image:pytorch-linux-jammy-py3-gcc11-inductor-benchmarks
      test-matrix: |
        { include: [
          { config: "cpu_operator_benchmark_short", shard: 1, num_shards: 1, runner: "linux.12xlarge" },
        ]}
    secrets: inherit

  opbenchmark-on-demand-build:
    if: ${{ github.event_name == 'workflow_dispatch' && github.repository_owner == 'pytorch' }}
    name: opbenchmark-on-demand-build
    uses: ./.github/workflows/_linux-build.yml
    with:
      build-environment: linux-jammy-py3.10-gcc11-build
      docker-image-name: ci-image:pytorch-linux-jammy-py3-gcc11-inductor-benchmarks
      test-matrix: |
        { include: [
          { config: "cpu_operator_benchmark_${{ inputs.test_mode }}", shard: 1, num_shards: 1, runner: "linux.12xlarge" },
        ]}
    secrets: inherit

  opbenchmark-test:
    name: opbenchmark-test
    uses: ./.github/workflows/_linux-test.yml
    needs: opbenchmark-build
    with:
      build-environment: linux-jammy-py3.10-gcc11-build
      docker-image: ${{ needs.opbenchmark-build.outputs.docker-image }}
      test-matrix: ${{ needs.opbenchmark-build.outputs.test-matrix }}
    secrets: inherit
