MLIR  20.0.0git
RunnerUtils.cpp
Go to the documentation of this file.
1 //===- RunnerUtils.cpp - Utils for MLIR exec on targets with a C++ runtime ===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements basic functions to debug structured MLIR types at
10 // runtime. Entities in this file may not be compatible with targets without a
11 // C++ runtime. These may be progressively migrated to CRunnerUtils.cpp over
12 // time.
13 //
14 //===----------------------------------------------------------------------===//
15 
17 #include <chrono>
18 
19 // NOLINTBEGIN(*-identifier-naming)
20 
22  std::cout << "Unranked Memref ";
24  std::cout << "\n";
25 }
26 
27 extern "C" void
29  std::cout << "Unranked Memref ";
31  std::cout << "\n";
32 }
33 
34 extern "C" void
36  std::cout << "Unranked Memref ";
38  std::cout << "\n";
39 }
40 
42  std::cout << "Unranked Memref ";
44  std::cout << "\n";
45 }
46 
47 extern "C" void
49  std::cout << "Unranked Memref ";
51  std::cout << "\n";
52 }
53 
54 extern "C" void
56  std::cout << "Unranked Memref ";
58  std::cout << "\n";
59 }
60 
61 extern "C" void
63  std::cout << "Unranked Memref ";
65  std::cout << "\n";
66 }
67 
68 extern "C" void
70  std::cout << "Unranked Memref ";
72  std::cout << "\n";
73 }
74 
78 }
79 
82 }
83 
86 }
87 
90 }
91 
94 }
95 
98 }
99 
101  impl::printMemRef(*M);
102 }
103 
105  impl::printMemRef(*M);
106 }
107 
109  impl::printMemRef(*M);
110 }
111 
112 extern "C" void
114  impl::printMemRef(*M);
115 }
116 
117 extern "C" void
119  impl::printMemRef(*M);
120 }
121 
122 extern "C" void
124  impl::printMemRef(*M);
125 }
126 
127 extern "C" int64_t _mlir_ciface_nanoTime() {
128  auto now = std::chrono::high_resolution_clock::now();
129  auto duration = now.time_since_epoch();
130  auto nanoseconds =
131  std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
132  return nanoseconds.count();
133 }
134 
135 extern "C" void printMemrefI32(int64_t rank, void *ptr) {
136  UnrankedMemRefType<int32_t> descriptor = {rank, ptr};
137  _mlir_ciface_printMemrefI32(&descriptor);
138 }
139 
140 extern "C" void printMemrefI64(int64_t rank, void *ptr) {
141  UnrankedMemRefType<int64_t> descriptor = {rank, ptr};
142  _mlir_ciface_printMemrefI64(&descriptor);
143 }
144 
145 extern "C" void printMemrefF32(int64_t rank, void *ptr) {
146  UnrankedMemRefType<float> descriptor = {rank, ptr};
147  _mlir_ciface_printMemrefF32(&descriptor);
148 }
149 
150 extern "C" void printMemrefF64(int64_t rank, void *ptr) {
151  UnrankedMemRefType<double> descriptor = {rank, ptr};
152  _mlir_ciface_printMemrefF64(&descriptor);
153 }
154 
155 // Assume index_type is in fact uint64_t.
156 static_assert(std::is_same<impl::index_type, uint64_t>::value,
157  "Expected index_type == uint64_t");
158 extern "C" void printMemrefInd(int64_t rank, void *ptr) {
159  UnrankedMemRefType<impl::index_type> descriptor = {rank, ptr};
160  _mlir_ciface_printMemrefInd(&descriptor);
161 }
162 
163 extern "C" void printMemrefC32(int64_t rank, void *ptr) {
164  UnrankedMemRefType<impl::complex32> descriptor = {rank, ptr};
165  _mlir_ciface_printMemrefC32(&descriptor);
166 }
167 
168 extern "C" void printMemrefC64(int64_t rank, void *ptr) {
169  UnrankedMemRefType<impl::complex64> descriptor = {rank, ptr};
170  _mlir_ciface_printMemrefC64(&descriptor);
171 }
172 
174  impl::printMemRef(*M);
175 }
177  impl::printMemRef(*M);
178 }
180  impl::printMemRef(*M);
181 }
183  impl::printMemRef(*M);
184 }
186  impl::printMemRef(*M);
187 }
188 
190  impl::printMemRef(*M);
191 }
192 
193 extern "C" void
195  impl::printMemRef(*M);
196 }
197 
198 extern "C" void
200  impl::printMemRef(*M);
201 }
202 
204  impl::printMemRef(*M);
205 }
206 
207 extern "C" void
209  impl::printMemRef(*M);
210 }
211 
212 extern "C" void
214  impl::printMemRef(*M);
215 }
216 
217 extern "C" void
219  impl::printMemRef(*M);
220 }
221 
222 extern "C" int64_t
224  UnrankedMemRefType<int8_t> *expected) {
225  return impl::verifyMemRef(*actual, *expected);
226 }
227 
228 extern "C" int64_t
230  UnrankedMemRefType<int16_t> *expected) {
231  return impl::verifyMemRef(*actual, *expected);
232 }
233 
234 extern "C" int64_t
236  UnrankedMemRefType<int32_t> *expected) {
237  return impl::verifyMemRef(*actual, *expected);
238 }
239 
240 extern "C" int64_t
242  UnrankedMemRefType<int64_t> *expected) {
243  return impl::verifyMemRef(*actual, *expected);
244 }
245 
246 extern "C" int64_t
248  UnrankedMemRefType<f16> *expected) {
249  return impl::verifyMemRef(*actual, *expected);
250 }
251 
252 extern "C" int64_t
254  UnrankedMemRefType<bf16> *expected) {
255  return impl::verifyMemRef(*actual, *expected);
256 }
257 
258 extern "C" int64_t
260  UnrankedMemRefType<float> *expected) {
261  return impl::verifyMemRef(*actual, *expected);
262 }
263 
264 extern "C" int64_t
266  UnrankedMemRefType<double> *expected) {
267  return impl::verifyMemRef(*actual, *expected);
268 }
269 
270 extern "C" int64_t
273  return impl::verifyMemRef(*actual, *expected);
274 }
275 
276 extern "C" int64_t
279  return impl::verifyMemRef(*actual, *expected);
280 }
281 
282 extern "C" int64_t
285  return impl::verifyMemRef(*actual, *expected);
286 }
287 
288 extern "C" int64_t verifyMemRefI32(int64_t rank, void *actualPtr,
289  void *expectedPtr) {
290  UnrankedMemRefType<int32_t> actualDesc = {rank, actualPtr};
291  UnrankedMemRefType<int32_t> expectedDesc = {rank, expectedPtr};
292  return _mlir_ciface_verifyMemRefI32(&actualDesc, &expectedDesc);
293 }
294 
295 extern "C" int64_t verifyMemRefF32(int64_t rank, void *actualPtr,
296  void *expectedPtr) {
297  UnrankedMemRefType<float> actualDesc = {rank, actualPtr};
298  UnrankedMemRefType<float> expectedDesc = {rank, expectedPtr};
299  return _mlir_ciface_verifyMemRefF32(&actualDesc, &expectedDesc);
300 }
301 
302 extern "C" int64_t verifyMemRefF64(int64_t rank, void *actualPtr,
303  void *expectedPtr) {
304  UnrankedMemRefType<double> actualDesc = {rank, actualPtr};
305  UnrankedMemRefType<double> expectedDesc = {rank, expectedPtr};
306  return _mlir_ciface_verifyMemRefF64(&actualDesc, &expectedDesc);
307 }
308 
309 extern "C" int64_t verifyMemRefInd(int64_t rank, void *actualPtr,
310  void *expectedPtr) {
311  UnrankedMemRefType<impl::index_type> actualDesc = {rank, actualPtr};
312  UnrankedMemRefType<impl::index_type> expectedDesc = {rank, expectedPtr};
313  return _mlir_ciface_verifyMemRefInd(&actualDesc, &expectedDesc);
314 }
315 
316 extern "C" int64_t verifyMemRefC32(int64_t rank, void *actualPtr,
317  void *expectedPtr) {
318  UnrankedMemRefType<impl::complex32> actualDesc = {rank, actualPtr};
319  UnrankedMemRefType<impl::complex32> expectedDesc = {rank, expectedPtr};
320  return _mlir_ciface_verifyMemRefC32(&actualDesc, &expectedDesc);
321 }
322 
323 extern "C" int64_t verifyMemRefC64(int64_t rank, void *actualPtr,
324  void *expectedPtr) {
325  UnrankedMemRefType<impl::complex64> actualDesc = {rank, actualPtr};
326  UnrankedMemRefType<impl::complex64> expectedDesc = {rank, expectedPtr};
327  return _mlir_ciface_verifyMemRefC64(&actualDesc, &expectedDesc);
328 }
329 
330 // NOLINTEND(*-identifier-naming)
int64_t _mlir_ciface_verifyMemRefC32(UnrankedMemRefType< impl::complex32 > *actual, UnrankedMemRefType< impl::complex32 > *expected)
void _mlir_ciface_printMemrefShapeI64(UnrankedMemRefType< int64_t > *M)
Definition: RunnerUtils.cpp:35
void _mlir_ciface_printMemref1dF32(StridedMemRefType< float, 1 > *M)
void printMemrefF64(int64_t rank, void *ptr)
int64_t _mlir_ciface_verifyMemRefF16(UnrankedMemRefType< f16 > *actual, UnrankedMemRefType< f16 > *expected)
void _mlir_ciface_printMemref1dI32(StridedMemRefType< int32_t, 1 > *M)
int64_t verifyMemRefC32(int64_t rank, void *actualPtr, void *expectedPtr)
int64_t _mlir_ciface_verifyMemRefBF16(UnrankedMemRefType< bf16 > *actual, UnrankedMemRefType< bf16 > *expected)
void _mlir_ciface_printMemref4dF32(StridedMemRefType< float, 4 > *M)
void _mlir_ciface_printMemref0dF32(StridedMemRefType< float, 0 > *M)
void _mlir_ciface_printMemrefF16(UnrankedMemRefType< f16 > *M)
Definition: RunnerUtils.cpp:96
int64_t verifyMemRefC64(int64_t rank, void *actualPtr, void *expectedPtr)
int64_t _mlir_ciface_verifyMemRefI32(UnrankedMemRefType< int32_t > *actual, UnrankedMemRefType< int32_t > *expected)
void _mlir_ciface_printMemrefC32(UnrankedMemRefType< impl::complex32 > *M)
void printMemrefInd(int64_t rank, void *ptr)
void _mlir_ciface_printMemrefF64(UnrankedMemRefType< double > *M)
void printMemrefC32(int64_t rank, void *ptr)
int64_t _mlir_ciface_nanoTime()
void printMemrefF32(int64_t rank, void *ptr)
int64_t _mlir_ciface_verifyMemRefF64(UnrankedMemRefType< double > *actual, UnrankedMemRefType< double > *expected)
void printMemrefI64(int64_t rank, void *ptr)
void _mlir_ciface_printMemref1dI8(StridedMemRefType< int8_t, 1 > *M)
void _mlir_ciface_printMemrefC64(UnrankedMemRefType< impl::complex64 > *M)
void _mlir_ciface_printMemrefBF16(UnrankedMemRefType< bf16 > *M)
int64_t _mlir_ciface_verifyMemRefC64(UnrankedMemRefType< impl::complex64 > *actual, UnrankedMemRefType< impl::complex64 > *expected)
void _mlir_ciface_printMemref1dI64(StridedMemRefType< int64_t, 1 > *M)
void _mlir_ciface_printMemrefShapeF32(UnrankedMemRefType< float > *M)
Definition: RunnerUtils.cpp:41
int64_t verifyMemRefF32(int64_t rank, void *actualPtr, void *expectedPtr)
int64_t _mlir_ciface_verifyMemRefI64(UnrankedMemRefType< int64_t > *actual, UnrankedMemRefType< int64_t > *expected)
void _mlir_ciface_printMemref1dC32(StridedMemRefType< impl::complex32, 1 > *M)
void _mlir_ciface_printMemrefShapeF64(UnrankedMemRefType< double > *M)
Definition: RunnerUtils.cpp:48
void _mlir_ciface_printMemref1dC64(StridedMemRefType< impl::complex64, 1 > *M)
void _mlir_ciface_printMemrefI8(UnrankedMemRefType< int8_t > *M)
Definition: RunnerUtils.cpp:80
void _mlir_ciface_printMemrefI32(UnrankedMemRefType< int32_t > *M)
Definition: RunnerUtils.cpp:88
void _mlir_ciface_printMemrefShapeI32(UnrankedMemRefType< int32_t > *M)
Definition: RunnerUtils.cpp:28
int64_t verifyMemRefF64(int64_t rank, void *actualPtr, void *expectedPtr)
void _mlir_ciface_printMemref1dInd(StridedMemRefType< impl::index_type, 1 > *M)
void _mlir_ciface_printMemrefI16(UnrankedMemRefType< int16_t > *M)
Definition: RunnerUtils.cpp:84
void _mlir_ciface_printMemrefInd(UnrankedMemRefType< impl::index_type > *M)
void _mlir_ciface_printMemrefShapeC64(UnrankedMemRefType< impl::complex64 > *M)
Definition: RunnerUtils.cpp:69
int64_t _mlir_ciface_verifyMemRefI16(UnrankedMemRefType< int16_t > *actual, UnrankedMemRefType< int16_t > *expected)
void _mlir_ciface_printMemrefShapeC32(UnrankedMemRefType< impl::complex32 > *M)
Definition: RunnerUtils.cpp:62
int64_t _mlir_ciface_verifyMemRefI8(UnrankedMemRefType< int8_t > *actual, UnrankedMemRefType< int8_t > *expected)
void _mlir_ciface_printMemref1dF64(StridedMemRefType< double, 1 > *M)
void _mlir_ciface_printMemrefShapeInd(UnrankedMemRefType< impl::index_type > *M)
Definition: RunnerUtils.cpp:55
void printMemrefI32(int64_t rank, void *ptr)
void _mlir_ciface_printMemrefF32(UnrankedMemRefType< float > *M)
int64_t _mlir_ciface_verifyMemRefF32(UnrankedMemRefType< float > *actual, UnrankedMemRefType< float > *expected)
void _mlir_ciface_printMemref2dF32(StridedMemRefType< float, 2 > *M)
int64_t _mlir_ciface_verifyMemRefInd(UnrankedMemRefType< impl::index_type > *actual, UnrankedMemRefType< impl::index_type > *expected)
void _mlir_ciface_printMemrefVector4x4xf32(StridedMemRefType< Vector2D< 4, 4, float >, 2 > *M)
Definition: RunnerUtils.cpp:75
void _mlir_ciface_printMemrefI64(UnrankedMemRefType< int64_t > *M)
Definition: RunnerUtils.cpp:92
int64_t verifyMemRefInd(int64_t rank, void *actualPtr, void *expectedPtr)
void _mlir_ciface_printMemref3dF32(StridedMemRefType< float, 3 > *M)
void _mlir_ciface_printMemrefShapeI8(UnrankedMemRefType< int8_t > *M)
Definition: RunnerUtils.cpp:21
int64_t verifyMemRefI32(int64_t rank, void *actualPtr, void *expectedPtr)
void printMemrefC64(int64_t rank, void *ptr)
void printMemRefMetaData(StreamType &os, const DynamicMemRefType< T > &v)
Definition: RunnerUtils.h:44
int64_t verifyMemRef(const DynamicMemRefType< T > &actual, const DynamicMemRefType< T > &expected)
Verify the equivalence of two dynamic memrefs and return the number of errors or -1 if the shape of t...
Definition: RunnerUtils.h:320
void printMemRef(const DynamicMemRefType< T > &m)
Definition: RunnerUtils.h:218
StridedMemRef descriptor type with static rank.
Definition: CRunnerUtils.h:131