tvm
Loading...
Searching...
No Matches
cublas.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_CUBLAS_H_
25#define TVM_TOPI_CONTRIB_CUBLAS_H_
26
27#include <tvm/te/operation.h>
29
30namespace tvm {
31namespace topi {
32namespace contrib {
33
34using namespace tvm::te;
35using namespace topi::detail;
46inline Tensor cublas_matmul(const Tensor& lhs, const Tensor& rhs, bool transa, bool transb) {
47 auto n = transa ? lhs->shape[1] : lhs->shape[0];
48 auto m = transb ? rhs->shape[0] : rhs->shape[1];
49
50 return make_extern(
51 {{n, m}}, {lhs->GetDataType()}, {lhs, rhs},
52 [&](ffi::Array<BufferVar> ins, ffi::Array<BufferVar> outs) {
53 return call_packed({prim::StringImm("tvm.contrib.cublas.matmul"), pack_buffer(ins[0]),
54 pack_buffer(ins[1]), pack_buffer(outs[0]), IntImm::Int32(transa),
56 },
57 "C", "", {})[0];
58}
59
71inline Tensor cublas_batch_matmul(const Tensor& lhs, const Tensor& rhs, bool transa, bool transb) {
72 auto b = lhs->shape[0];
73 auto n = transa ? lhs->shape[2] : lhs->shape[1];
74 auto m = transb ? rhs->shape[1] : rhs->shape[2];
75
76 return make_extern(
77 {{b, n, m}}, {lhs->GetDataType()}, {lhs, rhs},
78 [&](ffi::Array<BufferVar> ins, ffi::Array<BufferVar> outs) {
79 return call_packed({prim::StringImm("tvm.contrib.cublas.batch_matmul"), pack_buffer(ins[0]),
80 pack_buffer(ins[1]), pack_buffer(outs[0]), IntImm::Int32(transa),
82 },
83 "C", "", {})[0];
84}
85
86} // namespace contrib
87} // namespace topi
88} // namespace tvm
89
90#endif // TVM_TOPI_CONTRIB_CUBLAS_H_
static IntImm Int32(int64_t value, Span span=Span())
Construct a scalar int32 constant.
Definition expr.h:528
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
Managed reference to StringImmNode.
Definition expr.h:68
Tensor structure representing a possible input, or intermediate computation result.
Definition tensor.h:98
Helpers for using external functions.
Tensor expression language DSL.
Definition extracted_task.h:33
Tensor cublas_matmul(const Tensor &lhs, const Tensor &rhs, bool transa, bool transb)
Create an op that multiplies lhs and rhs with cuBLAS.
Definition cublas.h:46
Tensor cublas_batch_matmul(const Tensor &lhs, const Tensor &rhs, bool transa, bool transb)
Create an op that multiplies batch matrices lhs and rhs with cuBLAS.
Definition cublas.h:71
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
Operation node can generate one or multiple Tensors.