name: xpu

on:
  push:
    tags:
      - ciflow/xpu/*
  workflow_dispatch:
  schedule:
    # Run 3 times on weekdays and less frequently on weekends.
    - cron: 45 0,8,16 * * 1-5
    - cron: 45 4 * * 0,6

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

jobs:

  get-label-type:
    if: github.repository_owner == 'pytorch'
    name: get-label-type
    uses: pytorch/pytorch/.github/workflows/_runner-determinator.yml@main
    with:
      triggering_actor: ${{ github.triggering_actor }}
      issue_owner: ${{ github.event.pull_request.user.login || github.event.issue.user.login }}
      curr_branch: ${{ github.head_ref || github.ref_name }}
      curr_ref_type: ${{ github.ref_type }}

  linux-jammy-xpu-n-1-py3_10-build:
    name: linux-jammy-xpu-n-1-py3.10
    uses: ./.github/workflows/_linux-build.yml
    needs: get-label-type
    with:
      sync-tag: linux-xpu-n-1-build
      runner_prefix: ${{ needs.get-label-type.outputs.label-type }}
      build-environment: linux-jammy-xpu-n-1-py3.10
      docker-image-name: ci-image:pytorch-linux-jammy-xpu-n-1-py3
      runner: linux.12xlarge
      test-matrix: |
        { include: [
          { config: "default", shard: 1, num_shards: 6, runner: "linux.idc.xpu" },
          { config: "default", shard: 2, num_shards: 6, runner: "linux.idc.xpu" },
          { config: "default", shard: 3, num_shards: 6, runner: "linux.idc.xpu" },
          { config: "default", shard: 4, num_shards: 6, runner: "linux.idc.xpu" },
          { config: "default", shard: 5, num_shards: 6, runner: "linux.idc.xpu" },
          { config: "default", shard: 6, num_shards: 6, runner: "linux.idc.xpu" },
        ]}
    secrets: inherit

  linux-jammy-xpu-n-py3_10-build:
    name: linux-jammy-xpu-n-py3.10
    uses: ./.github/workflows/_linux-build.yml
    needs: get-label-type
    with:
      sync-tag: linux-xpu-n-build
      runner_prefix: ${{ needs.get-label-type.outputs.label-type }}
      build-environment: linux-jammy-xpu-n-py3.10
      docker-image-name: ci-image:pytorch-linux-jammy-xpu-n-py3
      runner: linux.12xlarge
      test-matrix: |
        { include: [
          { config: "default", shard: 1, num_shards: 8, runner: "linux.idc.xpu" },
          { config: "default", shard: 2, num_shards: 8, runner: "linux.idc.xpu" },
          { config: "default", shard: 3, num_shards: 8, runner: "linux.idc.xpu" },
          { config: "default", shard: 4, num_shards: 8, runner: "linux.idc.xpu" },
          { config: "default", shard: 5, num_shards: 8, runner: "linux.idc.xpu" },
          { config: "default", shard: 6, num_shards: 8, runner: "linux.idc.xpu" },
          { config: "default", shard: 7, num_shards: 8, runner: "linux.idc.xpu" },
          { config: "default", shard: 8, num_shards: 8, runner: "linux.idc.xpu" },
        ]}
    secrets: inherit

  linux-jammy-xpu-n-py3_10-test:
    name: linux-jammy-xpu-n-py3.10
    uses: ./.github/workflows/_xpu-test.yml
    needs: linux-jammy-xpu-n-py3_10-build
    permissions:
      id-token: write
      contents: read
    with:
      build-environment: linux-jammy-xpu-n-py3.10
      docker-image: ${{ needs.linux-jammy-xpu-n-py3_10-build.outputs.docker-image }}
      test-matrix: ${{ needs.linux-jammy-xpu-n-py3_10-build.outputs.test-matrix }}
    secrets: inherit

  windows-xpu-n-1-build:
    if: github.repository_owner == 'pytorch'
    name: win-vs2022-xpu-n-1-py3
    uses: ./.github/workflows/_win-build.yml
    with:
      build-environment: win-vs2022-xpu-n-1-py3
      cuda-version: cpu
      use-xpu: true
      xpu-version: '2025.1'
      vc-year: '2022'
    secrets: inherit

  windows-xpu-n-build:
    if: github.repository_owner == 'pytorch'
    name: win-vs2022-xpu-n-py3
    uses: ./.github/workflows/_win-build.yml
    with:
      build-environment: win-vs2022-xpu-n-py3
      cuda-version: cpu
      use-xpu: true
      xpu-version: '2025.2'
      vc-year: '2022'
    secrets: inherit
