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
20/*!
21 * \file target/target_info.cc
22 */
23#include <tvm/node/repr_printer.h>
24#include <tvm/runtime/registry.h>
25#include <tvm/target/target_info.h>
26
27namespace tvm {
28
29TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable)
30 .set_dispatch<MemoryInfoNode>([](const ObjectRef& node, ReprPrinter* p) {
31 auto* op = static_cast<const MemoryInfoNode*>(node.get());
32 p->stream << "mem-info("
33 << "unit_bits=" << op->unit_bits << ", "
34 << "max_num_bits=" << op->max_num_bits << ", "
35 << "max_simd_bits=" << op->max_simd_bits << ", "
36 << "head_address=" << op->head_address << ")";
37 });
38
39TVM_REGISTER_NODE_TYPE(MemoryInfoNode);
40
41MemoryInfo GetMemoryInfo(const std::string& scope) {
42 std::string fname = "tvm.info.mem." + scope;
43 const runtime::PackedFunc* f = runtime::Registry::Get(fname);
44 if (f == nullptr) {
45 LOG(WARNING) << "MemoryInfo for scope = " << scope << " is undefined";
46 return MemoryInfo();
47 } else {
48 return (*f)();
49 }
50}
51
52} // namespace tvm
53