tvm
Loading...
Searching...
No Matches
thread_scope.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 */
23#ifndef TVM_TIRX_TILE_THREAD_SCOPE_H_
24#define TVM_TIRX_TILE_THREAD_SCOPE_H_
25#include <tvm/ffi/enum.h>
26#include <tvm/ffi/reflection/enum_def.h>
27#include <tvm/runtime/base.h>
28
29#include <ostream>
30
31namespace tvm::tirx {
32
33namespace thread_scope_attr {
35inline constexpr ffi::reflection::AttrKey<ffi::String> kBackend{"backend"};
37inline constexpr ffi::reflection::AttrKey<int64_t> kRank{"rank"};
38} // namespace thread_scope_attr
39
40class ThreadScopeObj : public ffi::EnumObj {
41 public:
42 const ffi::String& name() const { return _str_index; }
43 TVM_TIRX_DLL ffi::String backend() const;
44 TVM_TIRX_DLL ffi::String local_name() const;
45 TVM_TIRX_DLL int64_t rank() const;
46 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.ThreadScope", ThreadScopeObj, ffi::EnumObj);
47};
48
55class ThreadScope : public ffi::Enum {
56 public:
57 explicit ThreadScope(const ffi::String& name) : ffi::Enum(Get(name)) {}
58 TVM_TIRX_DLL static ThreadScope Get(const ffi::String& name);
59 const ffi::String& name() const { return get()->name(); }
60 bool operator==(const ThreadScope& other) const { return same_as(other); }
61 bool operator!=(const ThreadScope& other) const { return !same_as(other); }
63};
64
67
68inline std::ostream& operator<<(std::ostream& os, const ThreadScope& scope) {
69 return os << scope.name();
70}
71
72} // namespace tvm::tirx
73
74namespace tvm::ffi {
75template <>
76inline constexpr bool use_default_type_traits_v<tirx::ThreadScope> = false;
77template <>
78struct TypeTraits<tirx::ThreadScope>
79 : public ObjectRefWithFallbackTraitsBase<tirx::ThreadScope, ffi::String> {
80 static tirx::ThreadScope ConvertFallbackValue(ffi::String name) {
81 return tirx::ThreadScope::Get(name);
82 }
83};
84} // namespace tvm::ffi
85#endif // TVM_TIRX_TILE_THREAD_SCOPE_H_
#define TVM_TIRX_DLL
Definition base.h:55
Definition thread_scope.h:40
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.ThreadScope", ThreadScopeObj, ffi::EnumObj)
const ffi::String & name() const
Definition thread_scope.h:42
TVM_TIRX_DLL ffi::String local_name() const
TVM_TIRX_DLL ffi::String backend() const
TVM_TIRX_DLL int64_t rank() const
Canonical thread-scope identity, named as backend.scope.
Definition thread_scope.h:55
ThreadScope(const ffi::String &name)
Definition thread_scope.h:57
static TVM_TIRX_DLL ThreadScope Get(const ffi::String &name)
bool operator!=(const ThreadScope &other) const
Definition thread_scope.h:61
bool operator==(const ThreadScope &other) const
Definition thread_scope.h:60
const ffi::String & name() const
Definition thread_scope.h:59
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ThreadScope, ffi::Enum, ThreadScopeObj)
Definition nested_msg.h:600
constexpr ffi::reflection::AttrKey< ffi::String > kBackend
Backend owning a thread scope.
Definition thread_scope.h:35
constexpr ffi::reflection::AttrKey< int64_t > kRank
Explicit hierarchy rank. Smaller ranks denote wider scopes.
Definition thread_scope.h:37
Definition axis_group_graph.h:41
std::ostream & operator<<(std::ostream &os, const ThreadScope &scope)
Definition thread_scope.h:68
TVM_TIRX_DLL bool ScopeHigher(const ThreadScope &a, const ThreadScope &b)
Compare explicit ranks within one backend's hierarchy.
static tirx::ThreadScope ConvertFallbackValue(ffi::String name)
Definition thread_scope.h:80