|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +# pylint: disable=invalid-name,missing-function-docstring |
| 18 | +"""Intrinsics for AMDGPU tensorization.""" |
| 19 | +from tvm.script import tir as T |
| 20 | +from .. import TensorIntrin |
| 21 | +from .dot_product_common import dp4a_desc |
| 22 | + |
| 23 | + |
| 24 | +@T.prim_func |
| 25 | +def sdot4( |
| 26 | + A: T.Buffer((4,), "int8", offset_factor=1, align=4, scope="shared"), |
| 27 | + B: T.Buffer((4,), "int8", offset_factor=1, align=4, scope="shared"), |
| 28 | + C: T.Buffer((1,), "int32", offset_factor=1, align=4, scope="local"), |
| 29 | +) -> None: |
| 30 | + with T.block("root"): |
| 31 | + T.reads(C[0], A[0:4], B[0:4]) |
| 32 | + T.writes(C[0]) |
| 33 | + |
| 34 | + C[0] += T.call_llvm_pure_intrin( |
| 35 | + T.llvm_lookup_intrinsic_id("llvm.amdgcn.sdot4"), |
| 36 | + T.uint32(4), |
| 37 | + T.reinterpret(A.vload([0], "int8x4"), dtype="int32"), |
| 38 | + T.reinterpret(B.vload([0], "int8x4"), dtype="int32"), |
| 39 | + T.int32(0), |
| 40 | + T.bool(1), |
| 41 | + dtype="int32" |
| 42 | + ) |
| 43 | + |
| 44 | + |
| 45 | +AMDGPU_SDOT4_INTRIN = "sdot4" |
| 46 | + |
| 47 | +TensorIntrin.register(AMDGPU_SDOT4_INTRIN, dp4a_desc, sdot4) |
0 commit comments