chore: import upstream snapshot with attribution
Lint / lint (push) Has been cancelled
CI / MacOS (push) Has been cancelled
CI / Windows (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:36:25 +08:00
commit 26446540fa
3151 changed files with 974126 additions and 0 deletions
@@ -0,0 +1,29 @@
<!--- Licensed to the Apache Software Foundation (ASF) under one -->
<!--- or more contributor license agreements. See the NOTICE file -->
<!--- distributed with this work for additional information -->
<!--- regarding copyright ownership. The ASF licenses this file -->
<!--- to you under the Apache License, Version 2.0 (the -->
<!--- "License"); you may not use this file except in compliance -->
<!--- with the License. You may obtain a copy of the License at -->
<!--- http://www.apache.org/licenses/LICENSE-2.0 -->
<!--- Unless required by applicable law or agreed to in writing, -->
<!--- software distributed under the License is distributed on an -->
<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
<!--- KIND, either express or implied. See the License for the -->
<!--- specific language governing permissions and limitations -->
<!--- under the License. -->
# Core Cross Platform Regression Tests
CI Unit test cases that will run on all platforms.
To reduce the CI burden, we only put in test-cases that are platform sensitive.
Please use the following guideline:
- Always consider add tests to the unittest folder first.
- If a problems that passes the Linux pipeline but fails in Windows or MacOS,
we should isolate the problem, write a minimal regression test case
and add it to this folder.
- A test case in this folder should be minimal and finish in a reasonable amount of time.
- Document about why it should be in the all-platform-minimal-test.
@@ -0,0 +1,63 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ruff: noqa: F401
"""LLVM enablement tests."""
import ctypes
import math
import re
import numpy as np
import pytest
import tvm
import tvm.testing
from tvm import te, topi
from tvm.support import utils
from tvm.testing import env
@pytest.mark.skipif(not env.has_llvm(), reason="need llvm")
def test_llvm_add_pipeline():
"""all-platform-minimal-test: Check LLVM enablement."""
nn = 128
n = tvm.runtime.convert(nn)
A = te.placeholder((n,), name="A")
B = te.placeholder((n,), name="B")
AA = te.compute((n,), lambda *i: A(*i), name="A")
BB = te.compute((n,), lambda *i: B(*i), name="B")
T = te.compute(A.shape, lambda *i: AA(*i) + BB(*i), name="T")
C = te.compute(A.shape, lambda *i: T(*i), name="C")
sch = tvm.s_tir.Schedule(te.create_prim_func([A, B, C]))
xo, xi = sch.split(sch.get_loops("C")[0], factors=[None, 4])
sch.parallel(xo)
sch.vectorize(xi)
def check_llvm():
# BUILD and invoke the kernel.
f = tvm.compile(sch.mod, target="llvm")
dev = tvm.cpu(0)
# launch the kernel.
n = nn
a = tvm.runtime.tensor(np.random.uniform(size=n).astype(A.dtype), dev)
b = tvm.runtime.tensor(np.random.uniform(size=n).astype(B.dtype), dev)
c = tvm.runtime.tensor(np.zeros(n, dtype=C.dtype), dev)
f(a, b, c)
tvm.testing.assert_allclose(c.numpy(), a.numpy() + b.numpy())
check_llvm()
@@ -0,0 +1,56 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""Post-install checks for a built TVM wheel.
These live in ``tests/python/all-platform-minimal-test`` so the standard suite and
the cibuildwheel ``test-command`` run a single pytest invocation. The assertions
here are wheel-specific things the rest of the suite cannot check -- that LLVM is
enabled (the other LLVM test merely *skips* when LLVM is absent) and that the CUDA
runtime library got bundled -- so each is gated behind a ``TVM_WHEEL_EXPECT_*`` env
var and SKIPS unless that var is set. cibuildwheel sets the vars (see
``CIBW_TEST_ENVIRONMENT`` in ``.github/actions/build-wheel-for-publish``); ordinary
source-build CI (e.g. ``main.yml``) leaves them unset, so these tests skip there and
never fail a non-wheel / non-LLVM / non-CUDA build.
"""
import glob
import os
from pathlib import Path
import pytest
import tvm
def test_llvm_enabled():
"""Every published TVM wheel ships with LLVM enabled. Only assert this when
validating a wheel (``TVM_WHEEL_EXPECT_LLVM=1``); skip otherwise so source
builds with LLVM off do not fail."""
if os.environ.get("TVM_WHEEL_EXPECT_LLVM") != "1":
pytest.skip("LLVM enablement only asserted during wheel validation")
assert tvm.runtime.enabled("llvm"), "wheel was not built with LLVM enabled"
def test_cuda_runtime_present():
"""The bundled CUDA runtime library must be present in tvm/lib."""
if os.environ.get("TVM_WHEEL_EXPECT_CUDA_RUNTIME") != "1":
pytest.skip("CUDA runtime not expected in this wheel")
libdir = Path(tvm.__file__).resolve().parent / "lib"
present = glob.glob(str(libdir / "libtvm_runtime_cuda.*")) or glob.glob(
str(libdir / "tvm_runtime_cuda.*")
)
assert present, "CUDA runtime expected but not bundled in tvm/lib"