File: vce-deduction.mlir

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (209 lines) | stat: -rw-r--r-- 8,059 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// RUN: mlir-opt -spirv-update-vce %s | FileCheck %s

//===----------------------------------------------------------------------===//
// Version
//===----------------------------------------------------------------------===//

// Test deducing minimal version.
// spirv.IAdd is available from v1.0.

// CHECK: requires #spirv.vce<v1.0, [Shader], []>
spirv.module Logical GLSL450 attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.5, [Shader], []>, #spirv.resource_limits<>>
} {
  spirv.func @iadd(%val : i32) -> i32 "None" {
    %0 = spirv.IAdd %val, %val: i32
    spirv.ReturnValue %0: i32
  }
}

// Test deducing minimal version.
// spirv.GroupNonUniformBallot is available since v1.3.

// CHECK: requires #spirv.vce<v1.3, [GroupNonUniformBallot, Shader], []>
spirv.module Logical GLSL450 attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.5, [Shader, GroupNonUniformBallot], []>, #spirv.resource_limits<>>
} {
  spirv.func @group_non_uniform_ballot(%predicate : i1) -> vector<4xi32> "None" {
    %0 = spirv.GroupNonUniformBallot <Workgroup> %predicate : vector<4xi32>
    spirv.ReturnValue %0: vector<4xi32>
  }
}

//===----------------------------------------------------------------------===//
// Capability
//===----------------------------------------------------------------------===//

// Test minimal capabilities.

// CHECK: requires #spirv.vce<v1.0, [Shader], []>
spirv.module Logical GLSL450 attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.0, [Shader, Float16, Float64, Int16, Int64, VariablePointers], []>, #spirv.resource_limits<>>
} {
  spirv.func @iadd(%val : i32) -> i32 "None" {
    %0 = spirv.IAdd %val, %val: i32
    spirv.ReturnValue %0: i32
  }
}

// Test Physical Storage Buffers are deduced correctly.

// CHECK: spirv.module PhysicalStorageBuffer64 GLSL450 requires #spirv.vce<v1.0, [PhysicalStorageBufferAddresses, Shader], [SPV_EXT_physical_storage_buffer]>
spirv.module PhysicalStorageBuffer64 GLSL450 attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.0, [Shader, PhysicalStorageBufferAddresses], [SPV_EXT_physical_storage_buffer]>, #spirv.resource_limits<>>
} {
  spirv.func @physical_ptr(%val : !spirv.ptr<f32, PhysicalStorageBuffer>) "None" {
    spirv.Return
  }
}

// Test deducing implied capability.
// AtomicStorage implies Shader.

// CHECK: requires #spirv.vce<v1.0, [Shader], []>
spirv.module Logical GLSL450 attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.0, [AtomicStorage], []>, #spirv.resource_limits<>>
} {
  spirv.func @iadd(%val : i32) -> i32 "None" {
    %0 = spirv.IAdd %val, %val: i32
    spirv.ReturnValue %0: i32
  }
}

// Test selecting the capability available in the target environment.
// spirv.GroupNonUniform op itself can be enabled via any of
// * GroupNonUniformArithmetic
// * GroupNonUniformClustered
// * GroupNonUniformPartitionedNV
// Its 'Reduce' group operation can be enabled via any of
// * Kernel
// * GroupNonUniformArithmetic
// * GroupNonUniformBallot

// CHECK: requires #spirv.vce<v1.3, [GroupNonUniformArithmetic, Shader], []>
spirv.module Logical GLSL450 attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.3, [Shader, GroupNonUniformArithmetic], []>, #spirv.resource_limits<>>
} {
  spirv.func @group_non_uniform_iadd(%val : i32) -> i32 "None" {
    %0 = spirv.GroupNonUniformIAdd "Subgroup" "Reduce" %val : i32
    spirv.ReturnValue %0: i32
  }
}

// CHECK: requires #spirv.vce<v1.3, [GroupNonUniformClustered, GroupNonUniformBallot, Shader], []>
spirv.module Logical GLSL450 attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.3, [Shader, GroupNonUniformClustered, GroupNonUniformBallot], []>, #spirv.resource_limits<>>
} {
  spirv.func @group_non_uniform_iadd(%val : i32) -> i32 "None" {
    %0 = spirv.GroupNonUniformIAdd "Subgroup" "Reduce" %val : i32
    spirv.ReturnValue %0: i32
  }
}

// Test type required capabilities

// Using 8-bit integers in non-interface storage class requires Int8.
// CHECK: requires #spirv.vce<v1.0, [Int8, Shader], []>
spirv.module Logical GLSL450 attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.3, [Shader, Int8], []>, #spirv.resource_limits<>>
} {
  spirv.func @iadd_function(%val : i8) -> i8 "None" {
    %0 = spirv.IAdd %val, %val : i8
    spirv.ReturnValue %0: i8
  }
}

// Using 16-bit floats in non-interface storage class requires Float16.
// CHECK: requires #spirv.vce<v1.0, [Float16, Shader], []>
spirv.module Logical GLSL450 attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.3, [Shader, Float16], []>, #spirv.resource_limits<>>
} {
  spirv.func @fadd_function(%val : f16) -> f16 "None" {
    %0 = spirv.FAdd %val, %val : f16
    spirv.ReturnValue %0: f16
  }
}

// Using 16-element vectors requires Vector16.
// CHECK: requires #spirv.vce<v1.0, [Vector16, Shader], []>
spirv.module Logical GLSL450 attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.3, [Shader, Vector16], []>, #spirv.resource_limits<>>
} {
  spirv.func @iadd_v16_function(%val : vector<16xi32>) -> vector<16xi32> "None" {
    %0 = spirv.IAdd %val, %val : vector<16xi32>
    spirv.ReturnValue %0: vector<16xi32>
  }
}

//===----------------------------------------------------------------------===//
// Extension
//===----------------------------------------------------------------------===//

// Test deducing minimal extensions.
// spirv.KHR.SubgroupBallot requires the SPV_KHR_shader_ballot extension.

// CHECK: requires #spirv.vce<v1.0, [SubgroupBallotKHR, Shader], [SPV_KHR_shader_ballot]>
spirv.module Logical GLSL450 attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.0, [Shader, SubgroupBallotKHR],
             [SPV_KHR_shader_ballot, SPV_KHR_shader_clock, SPV_KHR_variable_pointers]>, #spirv.resource_limits<>>
} {
  spirv.func @subgroup_ballot(%predicate : i1) -> vector<4xi32> "None" {
    %0 = spirv.KHR.SubgroupBallot %predicate: vector<4xi32>
    spirv.ReturnValue %0: vector<4xi32>
  }
}

// Test deducing implied extension.
// Vulkan memory model requires SPV_KHR_vulkan_memory_model, which is enabled
// implicitly by v1.5.

// CHECK: requires #spirv.vce<v1.0, [VulkanMemoryModel], [SPV_KHR_vulkan_memory_model]>
spirv.module Logical Vulkan attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.5, [Shader, VulkanMemoryModel], []>, #spirv.resource_limits<>>
} {
  spirv.func @iadd(%val : i32) -> i32 "None" {
    %0 = spirv.IAdd %val, %val: i32
    spirv.ReturnValue %0: i32
  }
}

// Test type required extensions

// Using 8-bit integers in interface storage class requires additional
// extensions and capabilities.
// CHECK: requires #spirv.vce<v1.0, [StorageBuffer16BitAccess, Shader, Int16], [SPV_KHR_16bit_storage, SPV_KHR_storage_buffer_storage_class]>
spirv.module Logical GLSL450 attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.3, [Shader, StorageBuffer16BitAccess, Int16], []>, #spirv.resource_limits<>>
} {
  spirv.func @iadd_storage_buffer(%ptr : !spirv.ptr<i16, StorageBuffer>) -> i16 "None" {
    %0 = spirv.Load "StorageBuffer" %ptr : i16
    %1 = spirv.IAdd %0, %0 : i16
    spirv.ReturnValue %1: i16
  }
}

// Complicated nested types
// * Buffer requires ImageBuffer or SampledBuffer.
// * Rg32f requires StorageImageExtendedFormats.
// CHECK: requires #spirv.vce<v1.0, [UniformAndStorageBuffer8BitAccess, StorageUniform16, Int64, Shader, ImageBuffer, StorageImageExtendedFormats], [SPV_KHR_8bit_storage, SPV_KHR_16bit_storage]>
spirv.module Logical GLSL450 attributes {
  spirv.target_env = #spirv.target_env<
    #spirv.vce<v1.5, [Shader, UniformAndStorageBuffer8BitAccess, StorageBuffer16BitAccess, StorageUniform16, Int16, Int64, ImageBuffer, StorageImageExtendedFormats], []>,
    #spirv.resource_limits<>>
} {
  spirv.GlobalVariable @data : !spirv.ptr<!spirv.struct<(i8 [0], f16 [2], i64 [4])>, Uniform>
  spirv.GlobalVariable @img  : !spirv.ptr<!spirv.image<f32, Buffer, NoDepth, NonArrayed, SingleSampled, SamplerUnknown, Rg32f>, UniformConstant>
}