Skip to main content

tvm_tirx/backend/cuda/
op.rs

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// The reflected field names `M`, `N`, and `K` are kept as they are.
20#![allow(non_snake_case)]
21// The generated constructors take one argument per reflected field.
22#![allow(clippy::too_many_arguments)]
23
24//! Attributes of CUDA instructions. [`TCGen05InstrDescriptorAttrs`] and
25//! [`TCGen05InstrDescriptorBlockScaledAttrs`] are the static options of a `tcgen05` instruction
26//! descriptor, and [`TensorMapEncodeTiledAttr`] those of a tiled tensor-map encoding.
27
28// tvm-ffi-stubgen(file): mod(missing_docs = allow)
29
30// tvm-ffi-stubgen(begin): import-section
31use crate::ir::attrs::Attrs;
32use crate::ir::attrs::AttrsObj;
33use std::ops::Deref;
34use tvm_ffi::DLDataType;
35use tvm_ffi::ObjectArc;
36use tvm_ffi::String;
37// tvm-ffi-stubgen(end)
38
39/// The static options of a dense `tcgen05` instruction descriptor, which
40/// `tirx.cuda.tcgen05_encode_instr_descriptor` encodes: the data types of the result `d_dtype` and
41/// the operands `a_dtype` and `b_dtype`, the shape `M` x `N` x `K`, the operand transposes, the
42/// number of CTA groups, operand negation, result saturation `sat_d` and sparsity.
43// tvm-ffi-stubgen(begin): object/tirx.cuda.TCGen05InstrDescriptorAttrs
44#[allow(missing_docs)]
45#[repr(C)]
46#[derive(tvm_ffi::derive::ObjectRef, Clone)]
47pub struct TCGen05InstrDescriptorAttrs {
48    data_: ObjectArc<TCGen05InstrDescriptorAttrsObj>,
49}
50
51/// The object behind [`TCGen05InstrDescriptorAttrs`].
52// Complete: reflected fields fill [24, 120) exactly (alignment padding [98, 104), [116, 120)).
53#[allow(non_snake_case)]
54#[allow(missing_docs)]
55#[repr(C)]
56#[derive(tvm_ffi::derive::Object)]
57#[object(type_key = "tirx.cuda.TCGen05InstrDescriptorAttrs", final, immutable)]
58pub struct TCGen05InstrDescriptorAttrsObj {
59    base_: AttrsObj,
60    pub d_dtype: String,
61    pub a_dtype: String,
62    pub b_dtype: String,
63    pub M: i64,
64    pub N: i64,
65    pub K: i64,
66    pub trans_a: bool,
67    pub trans_b: bool,
68    pub n_cta_groups: i64,
69    pub neg_a: bool,
70    pub neg_b: bool,
71    pub sat_d: bool,
72    pub is_sparse: bool,
73}
74
75const _: () = {
76    assert!(::core::mem::size_of::<TCGen05InstrDescriptorAttrsObj>() == 120);
77    assert!(::core::mem::align_of::<TCGen05InstrDescriptorAttrsObj>() == 8);
78};
79
80impl Deref for TCGen05InstrDescriptorAttrsObj {
81    type Target = AttrsObj;
82    fn deref(&self) -> &AttrsObj {
83        &self.base_
84    }
85}
86
87#[allow(missing_docs)]
88impl TCGen05InstrDescriptorAttrsObj {
89    #[allow(non_snake_case)]
90    pub(crate) fn new(
91        d_dtype: String,
92        a_dtype: String,
93        b_dtype: String,
94        M: i64,
95        N: i64,
96        K: i64,
97        trans_a: bool,
98        trans_b: bool,
99        n_cta_groups: i64,
100        neg_a: bool,
101        neg_b: bool,
102        sat_d: bool,
103        is_sparse: bool,
104    ) -> Self {
105        let base_ = AttrsObj::new();
106        Self {
107            base_,
108            d_dtype,
109            a_dtype,
110            b_dtype,
111            M,
112            N,
113            K,
114            trans_a,
115            trans_b,
116            n_cta_groups,
117            neg_a,
118            neg_b,
119            sat_d,
120            is_sparse,
121        }
122    }
123}
124
125#[allow(missing_docs)]
126impl TCGen05InstrDescriptorAttrs {
127    /// Create a `TCGen05InstrDescriptorAttrs` from its field values.
128    #[allow(non_snake_case)]
129    pub fn new(
130        d_dtype: impl Into<String>,
131        a_dtype: impl Into<String>,
132        b_dtype: impl Into<String>,
133        M: i64,
134        N: i64,
135        K: i64,
136        trans_a: bool,
137        trans_b: bool,
138        n_cta_groups: i64,
139        neg_a: bool,
140        neg_b: bool,
141        sat_d: bool,
142        is_sparse: bool,
143    ) -> Self {
144        let obj = TCGen05InstrDescriptorAttrsObj::new(
145            d_dtype.into(),
146            a_dtype.into(),
147            b_dtype.into(),
148            M,
149            N,
150            K,
151            trans_a,
152            trans_b,
153            n_cta_groups,
154            neg_a,
155            neg_b,
156            sat_d,
157            is_sparse,
158        );
159        Self { data_: ObjectArc::new(obj) }
160    }
161}
162
163tvm_ffi::impl_object_ref_upcast!(TCGen05InstrDescriptorAttrs => Attrs);
164// tvm-ffi-stubgen(end)
165
166/// The static options of a block-scaled `tcgen05` instruction descriptor, which
167/// `tirx.cuda.tcgen05_encode_instr_descriptor_block_scaled` encodes: those of
168/// [`TCGen05InstrDescriptorAttrs`] but saturation, and the data types of the scale factors
169/// `sfa_dtype` and `sfb_dtype`.
170// tvm-ffi-stubgen(begin): object/tirx.cuda.TCGen05InstrDescriptorBlockScaledAttrs
171#[allow(missing_docs)]
172#[repr(C)]
173#[derive(tvm_ffi::derive::ObjectRef, Clone)]
174pub struct TCGen05InstrDescriptorBlockScaledAttrs {
175    data_: ObjectArc<TCGen05InstrDescriptorBlockScaledAttrsObj>,
176}
177
178/// The object behind [`TCGen05InstrDescriptorBlockScaledAttrs`].
179// Complete: reflected fields fill [24, 152) exactly (alignment padding [130, 136), [147, 152)).
180#[allow(non_snake_case)]
181#[allow(missing_docs)]
182#[repr(C)]
183#[derive(tvm_ffi::derive::Object)]
184#[object(type_key = "tirx.cuda.TCGen05InstrDescriptorBlockScaledAttrs", final, immutable)]
185pub struct TCGen05InstrDescriptorBlockScaledAttrsObj {
186    base_: AttrsObj,
187    pub d_dtype: String,
188    pub a_dtype: String,
189    pub b_dtype: String,
190    pub sfa_dtype: String,
191    pub sfb_dtype: String,
192    pub M: i64,
193    pub N: i64,
194    pub K: i64,
195    pub trans_a: bool,
196    pub trans_b: bool,
197    pub n_cta_groups: i64,
198    pub neg_a: bool,
199    pub neg_b: bool,
200    pub is_sparse: bool,
201}
202
203const _: () = {
204    assert!(::core::mem::size_of::<TCGen05InstrDescriptorBlockScaledAttrsObj>() == 152);
205    assert!(::core::mem::align_of::<TCGen05InstrDescriptorBlockScaledAttrsObj>() == 8);
206};
207
208impl Deref for TCGen05InstrDescriptorBlockScaledAttrsObj {
209    type Target = AttrsObj;
210    fn deref(&self) -> &AttrsObj {
211        &self.base_
212    }
213}
214
215#[allow(missing_docs)]
216impl TCGen05InstrDescriptorBlockScaledAttrsObj {
217    #[allow(non_snake_case)]
218    pub(crate) fn new(
219        d_dtype: String,
220        a_dtype: String,
221        b_dtype: String,
222        sfa_dtype: String,
223        sfb_dtype: String,
224        M: i64,
225        N: i64,
226        K: i64,
227        trans_a: bool,
228        trans_b: bool,
229        n_cta_groups: i64,
230        neg_a: bool,
231        neg_b: bool,
232        is_sparse: bool,
233    ) -> Self {
234        let base_ = AttrsObj::new();
235        Self {
236            base_,
237            d_dtype,
238            a_dtype,
239            b_dtype,
240            sfa_dtype,
241            sfb_dtype,
242            M,
243            N,
244            K,
245            trans_a,
246            trans_b,
247            n_cta_groups,
248            neg_a,
249            neg_b,
250            is_sparse,
251        }
252    }
253}
254
255#[allow(missing_docs)]
256impl TCGen05InstrDescriptorBlockScaledAttrs {
257    /// Create a `TCGen05InstrDescriptorBlockScaledAttrs` from its field values.
258    #[allow(non_snake_case)]
259    pub fn new(
260        d_dtype: impl Into<String>,
261        a_dtype: impl Into<String>,
262        b_dtype: impl Into<String>,
263        sfa_dtype: impl Into<String>,
264        sfb_dtype: impl Into<String>,
265        M: i64,
266        N: i64,
267        K: i64,
268        trans_a: bool,
269        trans_b: bool,
270        n_cta_groups: i64,
271        neg_a: bool,
272        neg_b: bool,
273        is_sparse: bool,
274    ) -> Self {
275        let obj = TCGen05InstrDescriptorBlockScaledAttrsObj::new(
276            d_dtype.into(),
277            a_dtype.into(),
278            b_dtype.into(),
279            sfa_dtype.into(),
280            sfb_dtype.into(),
281            M,
282            N,
283            K,
284            trans_a,
285            trans_b,
286            n_cta_groups,
287            neg_a,
288            neg_b,
289            is_sparse,
290        );
291        Self { data_: ObjectArc::new(obj) }
292    }
293}
294
295tvm_ffi::impl_object_ref_upcast!(TCGen05InstrDescriptorBlockScaledAttrs => Attrs);
296// tvm-ffi-stubgen(end)
297
298/// The fixed options of a `tirx.cuda.tensormap_encode_tiled` call, which encodes a tiled tensor map
299/// at run time: the `descriptor_dtype` and `rank` of the tensor, and its interleave, swizzle, L2
300/// promotion, out-of-bounds fill and data-type options.
301// tvm-ffi-stubgen(begin): object/tirx.cuda.TensorMapEncodeTiledAttr
302#[allow(missing_docs)]
303#[repr(C)]
304#[derive(tvm_ffi::derive::ObjectRef, Clone)]
305pub struct TensorMapEncodeTiledAttr {
306    data_: ObjectArc<TensorMapEncodeTiledAttrObj>,
307}
308
309/// The object behind [`TensorMapEncodeTiledAttr`].
310// Complete: reflected fields fill [24, 80) exactly (alignment padding [28, 32)).
311#[allow(missing_docs)]
312#[repr(C)]
313#[derive(tvm_ffi::derive::Object)]
314#[object(type_key = "tirx.cuda.TensorMapEncodeTiledAttr", final, immutable)]
315pub struct TensorMapEncodeTiledAttrObj {
316    base_: AttrsObj,
317    pub descriptor_dtype: DLDataType,
318    pub rank: i64,
319    pub interleave: i64,
320    pub swizzle: i64,
321    pub l2_promotion: i64,
322    pub oob_fill: i64,
323    pub force_cu_dtype: i64,
324}
325
326const _: () = {
327    assert!(::core::mem::size_of::<TensorMapEncodeTiledAttrObj>() == 80);
328    assert!(::core::mem::align_of::<TensorMapEncodeTiledAttrObj>() == 8);
329};
330
331impl Deref for TensorMapEncodeTiledAttrObj {
332    type Target = AttrsObj;
333    fn deref(&self) -> &AttrsObj {
334        &self.base_
335    }
336}
337
338#[allow(missing_docs)]
339impl TensorMapEncodeTiledAttrObj {
340    pub(crate) fn new(
341        descriptor_dtype: DLDataType,
342        rank: i64,
343        interleave: i64,
344        swizzle: i64,
345        l2_promotion: i64,
346        oob_fill: i64,
347        force_cu_dtype: i64,
348    ) -> Self {
349        let base_ = AttrsObj::new();
350        Self {
351            base_,
352            descriptor_dtype,
353            rank,
354            interleave,
355            swizzle,
356            l2_promotion,
357            oob_fill,
358            force_cu_dtype,
359        }
360    }
361}
362
363#[allow(missing_docs)]
364impl TensorMapEncodeTiledAttr {
365    /// Create a `TensorMapEncodeTiledAttr` from its field values.
366    pub fn new(
367        descriptor_dtype: impl Into<DLDataType>,
368        rank: i64,
369        interleave: i64,
370        swizzle: i64,
371        l2_promotion: i64,
372        oob_fill: i64,
373        force_cu_dtype: i64,
374    ) -> Self {
375        let obj = TensorMapEncodeTiledAttrObj::new(
376            descriptor_dtype.into(),
377            rank,
378            interleave,
379            swizzle,
380            l2_promotion,
381            oob_fill,
382            force_cu_dtype,
383        );
384        Self { data_: ObjectArc::new(obj) }
385    }
386}
387
388tvm_ffi::impl_object_ref_upcast!(TensorMapEncodeTiledAttr => Attrs);
389// tvm-ffi-stubgen(end)