|
| 1 | +# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +#!/bin/sh |
| 16 | + |
| 17 | +# GCP detection: try multiple independent signals because newer machine types |
| 18 | +# do not expose SMBIOS to the guest, so the DMI path alone misses them. |
| 19 | +_is_gcp_host() { |
| 20 | + # gVNIC driver bound to at least one PCI device. |
| 21 | + for _d in /sys/bus/pci/drivers/gve/*:*; do |
| 22 | + [ -e "$_d" ] && return 0 |
| 23 | + done |
| 24 | + # Any PCI device with Google's vendor ID. |
| 25 | + for _v in /sys/bus/pci/devices/*/vendor; do |
| 26 | + [ -r "$_v" ] && [ "$(cat "$_v")" = "0x1ae0" ] && return 0 |
| 27 | + done |
| 28 | + # SMBIOS fallback for machine families that expose it. |
| 29 | + [ "$(cat /sys/class/dmi/id/product_name 2>/dev/null)" = "Google Compute Engine" ] && return 0 |
| 30 | + [ "$(cat /sys/class/dmi/id/sys_vendor 2>/dev/null)" = "Google" ] && return 0 |
| 31 | + return 1 |
| 32 | +} |
| 33 | + |
| 34 | +# Only gIB-capable GCP instance families expose mlx5 RDMA NICs. |
| 35 | +_has_nvidia_rdma_nic() { |
| 36 | + for _d in /sys/bus/pci/drivers/mlx5_core/*:*; do |
| 37 | + [ -e "$_d" ] && return 0 |
| 38 | + done |
| 39 | + return 1 |
| 40 | +} |
| 41 | + |
| 42 | +if _is_gcp_host && _has_nvidia_rdma_nic && \ |
| 43 | + [ -f /opt/gcp/nccl-plugins/lib64/libnccl-net-gcp.so ]; then |
| 44 | + export NCCL_NET_PLUGIN=gcp |
| 45 | + if [ -f /opt/gcp/nccl-plugins/lib64/libnccl-tuner-gcp.so ]; then |
| 46 | + export NCCL_TUNER_PLUGIN=gcp |
| 47 | + fi |
| 48 | + if [ -f /opt/gcp/nccl-plugins/lib64/libnccl-profiler-gcp.so ]; then |
| 49 | + export NCCL_PROFILER_PLUGIN=gcp |
| 50 | + fi |
| 51 | + if [ -f /opt/gcp/nccl-plugins/lib64/libnccl-env-gcp.so ]; then |
| 52 | + export NCCL_ENV_PLUGIN=gcp |
| 53 | + fi |
| 54 | + if [ -d /opt/gcp/nccl-plugins/configs ]; then |
| 55 | + export NCCL_TUNER_CONFIG_PATH=/opt/gcp/nccl-plugins/configs |
| 56 | + fi |
| 57 | +fi |
| 58 | + |
| 59 | +if [ "${NCCL_PROFILER_PLUGIN:-}" = gcp ]; then |
| 60 | + echo |
| 61 | + echo "NOTE: GCP NCCL telemetry enabled." |
| 62 | + echo " See https://docs.cloud.google.com/ai-hypercomputer/docs/nccl/comma" |
| 63 | + echo " for further information." |
| 64 | +fi |
| 65 | + |
| 66 | +unset -f _is_gcp_host |
| 67 | +unset -f _has_nvidia_rdma_nic |
| 68 | +unset _d |
| 69 | +unset _v |
0 commit comments