tvm
rocblas.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
24 #ifndef TVM_TOPI_CONTRIB_ROCBLAS_H_
25 #define TVM_TOPI_CONTRIB_ROCBLAS_H_
26 
27 #include <tvm/te/operation.h>
28 #include <tvm/topi/detail/extern.h>
29 
30 namespace tvm {
31 namespace topi {
32 namespace contrib {
33 
34 using namespace tvm::te;
45 inline Tensor rocblas_matmul(const Tensor& lhs, const Tensor& rhs, bool transa, bool transb) {
46  auto n = transa ? lhs->shape[1] : lhs->shape[0];
47  auto m = transb ? rhs->shape[0] : rhs->shape[1];
48 
49  return make_extern(
50  {{n, m}}, {lhs->dtype}, {lhs, rhs},
51  [&](Array<Buffer> ins, Array<Buffer> outs) {
52  return call_packed({StringImm("tvm.contrib.rocblas.matmul"), pack_buffer(ins[0]),
53  pack_buffer(ins[1]), pack_buffer(outs[0]), transa, transb});
54  },
55  "C", "", {})[0];
56 }
67 inline Tensor rocblas_batch_matmul(const Tensor& lhs, const Tensor& rhs, bool transa, bool transb) {
68  auto batch_size = lhs->shape[0];
69  auto n = transa ? lhs->shape[2] : lhs->shape[1];
70  auto m = transb ? rhs->shape[1] : rhs->shape[2];
71 
72  return make_extern(
73  {{batch_size, n, m}}, {lhs->dtype}, {lhs, rhs},
74  [&](Array<Buffer> ins, Array<Buffer> outs) {
75  return call_packed({StringImm("tvm.contrib.rocblas.batch_matmul"), pack_buffer(ins[0]),
76  pack_buffer(ins[1]), pack_buffer(outs[0]), transa, transb});
77  },
78  "C", "", {})[0];
79 }
80 
81 } // namespace contrib
82 } // namespace topi
83 } // namespace tvm
84 
85 #endif // TVM_TOPI_CONTRIB_ROCBLAS_H_
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Tensor structure representing a possible input, or intermediate computation result.
Definition: tensor.h:102
Managed reference to StringImmNode.
Definition: expr.h:78
Helpers for using external functions.
Tensor expression language DSL.
Definition: extracted_task.h:33
Tensor rocblas_matmul(const Tensor &lhs, const Tensor &rhs, bool transa, bool transb)
Create an op that multiplies lhs and rhs with rocBLAS.
Definition: rocblas.h:45
Tensor rocblas_batch_matmul(const Tensor &lhs, const Tensor &rhs, bool transa, bool transb)
Create an op that batch multiplies lhs and rhs with rocBLAS.
Definition: rocblas.h:67
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Operation node can generate one or multiple Tensors.