[rtsan] Remove mkfifoat interceptor (#116997)
[llvm-project.git] / mlir / lib / ExecutionEngine / RunnerUtils.cpp
blobeaa83bfc693f1146b130fee8a711826acd1f4be1
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.
14 //===----------------------------------------------------------------------===//
16 #include "mlir/ExecutionEngine/RunnerUtils.h"
17 #include <chrono>
19 // NOLINTBEGIN(*-identifier-naming)
21 extern "C" void _mlir_ciface_printMemrefShapeI8(UnrankedMemRefType<int8_t> *M) {
22 std::cout << "Unranked Memref ";
23 printMemRefMetaData(std::cout, DynamicMemRefType<int8_t>(*M));
24 std::cout << "\n";
27 extern "C" void
28 _mlir_ciface_printMemrefShapeI32(UnrankedMemRefType<int32_t> *M) {
29 std::cout << "Unranked Memref ";
30 printMemRefMetaData(std::cout, DynamicMemRefType<int32_t>(*M));
31 std::cout << "\n";
34 extern "C" void
35 _mlir_ciface_printMemrefShapeI64(UnrankedMemRefType<int64_t> *M) {
36 std::cout << "Unranked Memref ";
37 printMemRefMetaData(std::cout, DynamicMemRefType<int64_t>(*M));
38 std::cout << "\n";
41 extern "C" void _mlir_ciface_printMemrefShapeF32(UnrankedMemRefType<float> *M) {
42 std::cout << "Unranked Memref ";
43 printMemRefMetaData(std::cout, DynamicMemRefType<float>(*M));
44 std::cout << "\n";
47 extern "C" void
48 _mlir_ciface_printMemrefShapeF64(UnrankedMemRefType<double> *M) {
49 std::cout << "Unranked Memref ";
50 printMemRefMetaData(std::cout, DynamicMemRefType<double>(*M));
51 std::cout << "\n";
54 extern "C" void
55 _mlir_ciface_printMemrefShapeInd(UnrankedMemRefType<impl::index_type> *M) {
56 std::cout << "Unranked Memref ";
57 printMemRefMetaData(std::cout, DynamicMemRefType<impl::index_type>(*M));
58 std::cout << "\n";
61 extern "C" void
62 _mlir_ciface_printMemrefShapeC32(UnrankedMemRefType<impl::complex32> *M) {
63 std::cout << "Unranked Memref ";
64 printMemRefMetaData(std::cout, DynamicMemRefType<impl::complex32>(*M));
65 std::cout << "\n";
68 extern "C" void
69 _mlir_ciface_printMemrefShapeC64(UnrankedMemRefType<impl::complex64> *M) {
70 std::cout << "Unranked Memref ";
71 printMemRefMetaData(std::cout, DynamicMemRefType<impl::complex64>(*M));
72 std::cout << "\n";
75 extern "C" void _mlir_ciface_printMemrefVector4x4xf32(
76 StridedMemRefType<Vector2D<4, 4, float>, 2> *M) {
77 impl::printMemRef(*M);
80 extern "C" void _mlir_ciface_printMemrefI8(UnrankedMemRefType<int8_t> *M) {
81 impl::printMemRef(*M);
84 extern "C" void _mlir_ciface_printMemrefI16(UnrankedMemRefType<int16_t> *M) {
85 impl::printMemRef(*M);
88 extern "C" void _mlir_ciface_printMemrefI32(UnrankedMemRefType<int32_t> *M) {
89 impl::printMemRef(*M);
92 extern "C" void _mlir_ciface_printMemrefI64(UnrankedMemRefType<int64_t> *M) {
93 impl::printMemRef(*M);
96 extern "C" void _mlir_ciface_printMemrefF16(UnrankedMemRefType<f16> *M) {
97 impl::printMemRef(*M);
100 extern "C" void _mlir_ciface_printMemrefBF16(UnrankedMemRefType<bf16> *M) {
101 impl::printMemRef(*M);
104 extern "C" void _mlir_ciface_printMemrefF32(UnrankedMemRefType<float> *M) {
105 impl::printMemRef(*M);
108 extern "C" void _mlir_ciface_printMemrefF64(UnrankedMemRefType<double> *M) {
109 impl::printMemRef(*M);
112 extern "C" void
113 _mlir_ciface_printMemrefInd(UnrankedMemRefType<impl::index_type> *M) {
114 impl::printMemRef(*M);
117 extern "C" void
118 _mlir_ciface_printMemrefC32(UnrankedMemRefType<impl::complex32> *M) {
119 impl::printMemRef(*M);
122 extern "C" void
123 _mlir_ciface_printMemrefC64(UnrankedMemRefType<impl::complex64> *M) {
124 impl::printMemRef(*M);
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();
135 extern "C" void printMemrefI32(int64_t rank, void *ptr) {
136 UnrankedMemRefType<int32_t> descriptor = {rank, ptr};
137 _mlir_ciface_printMemrefI32(&descriptor);
140 extern "C" void printMemrefI64(int64_t rank, void *ptr) {
141 UnrankedMemRefType<int64_t> descriptor = {rank, ptr};
142 _mlir_ciface_printMemrefI64(&descriptor);
145 extern "C" void printMemrefF32(int64_t rank, void *ptr) {
146 UnrankedMemRefType<float> descriptor = {rank, ptr};
147 _mlir_ciface_printMemrefF32(&descriptor);
150 extern "C" void printMemrefF64(int64_t rank, void *ptr) {
151 UnrankedMemRefType<double> descriptor = {rank, ptr};
152 _mlir_ciface_printMemrefF64(&descriptor);
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);
163 extern "C" void printMemrefC32(int64_t rank, void *ptr) {
164 UnrankedMemRefType<impl::complex32> descriptor = {rank, ptr};
165 _mlir_ciface_printMemrefC32(&descriptor);
168 extern "C" void printMemrefC64(int64_t rank, void *ptr) {
169 UnrankedMemRefType<impl::complex64> descriptor = {rank, ptr};
170 _mlir_ciface_printMemrefC64(&descriptor);
173 extern "C" void _mlir_ciface_printMemref0dF32(StridedMemRefType<float, 0> *M) {
174 impl::printMemRef(*M);
176 extern "C" void _mlir_ciface_printMemref1dF32(StridedMemRefType<float, 1> *M) {
177 impl::printMemRef(*M);
179 extern "C" void _mlir_ciface_printMemref2dF32(StridedMemRefType<float, 2> *M) {
180 impl::printMemRef(*M);
182 extern "C" void _mlir_ciface_printMemref3dF32(StridedMemRefType<float, 3> *M) {
183 impl::printMemRef(*M);
185 extern "C" void _mlir_ciface_printMemref4dF32(StridedMemRefType<float, 4> *M) {
186 impl::printMemRef(*M);
189 extern "C" void _mlir_ciface_printMemref1dI8(StridedMemRefType<int8_t, 1> *M) {
190 impl::printMemRef(*M);
193 extern "C" void
194 _mlir_ciface_printMemref1dI32(StridedMemRefType<int32_t, 1> *M) {
195 impl::printMemRef(*M);
198 extern "C" void
199 _mlir_ciface_printMemref1dI64(StridedMemRefType<int64_t, 1> *M) {
200 impl::printMemRef(*M);
203 extern "C" void _mlir_ciface_printMemref1dF64(StridedMemRefType<double, 1> *M) {
204 impl::printMemRef(*M);
207 extern "C" void
208 _mlir_ciface_printMemref1dInd(StridedMemRefType<impl::index_type, 1> *M) {
209 impl::printMemRef(*M);
212 extern "C" void
213 _mlir_ciface_printMemref1dC32(StridedMemRefType<impl::complex32, 1> *M) {
214 impl::printMemRef(*M);
217 extern "C" void
218 _mlir_ciface_printMemref1dC64(StridedMemRefType<impl::complex64, 1> *M) {
219 impl::printMemRef(*M);
222 extern "C" int64_t
223 _mlir_ciface_verifyMemRefI8(UnrankedMemRefType<int8_t> *actual,
224 UnrankedMemRefType<int8_t> *expected) {
225 return impl::verifyMemRef(*actual, *expected);
228 extern "C" int64_t
229 _mlir_ciface_verifyMemRefI16(UnrankedMemRefType<int16_t> *actual,
230 UnrankedMemRefType<int16_t> *expected) {
231 return impl::verifyMemRef(*actual, *expected);
234 extern "C" int64_t
235 _mlir_ciface_verifyMemRefI32(UnrankedMemRefType<int32_t> *actual,
236 UnrankedMemRefType<int32_t> *expected) {
237 return impl::verifyMemRef(*actual, *expected);
240 extern "C" int64_t
241 _mlir_ciface_verifyMemRefI64(UnrankedMemRefType<int64_t> *actual,
242 UnrankedMemRefType<int64_t> *expected) {
243 return impl::verifyMemRef(*actual, *expected);
246 extern "C" int64_t
247 _mlir_ciface_verifyMemRefF16(UnrankedMemRefType<f16> *actual,
248 UnrankedMemRefType<f16> *expected) {
249 return impl::verifyMemRef(*actual, *expected);
252 extern "C" int64_t
253 _mlir_ciface_verifyMemRefBF16(UnrankedMemRefType<bf16> *actual,
254 UnrankedMemRefType<bf16> *expected) {
255 return impl::verifyMemRef(*actual, *expected);
258 extern "C" int64_t
259 _mlir_ciface_verifyMemRefF32(UnrankedMemRefType<float> *actual,
260 UnrankedMemRefType<float> *expected) {
261 return impl::verifyMemRef(*actual, *expected);
264 extern "C" int64_t
265 _mlir_ciface_verifyMemRefF64(UnrankedMemRefType<double> *actual,
266 UnrankedMemRefType<double> *expected) {
267 return impl::verifyMemRef(*actual, *expected);
270 extern "C" int64_t
271 _mlir_ciface_verifyMemRefInd(UnrankedMemRefType<impl::index_type> *actual,
272 UnrankedMemRefType<impl::index_type> *expected) {
273 return impl::verifyMemRef(*actual, *expected);
276 extern "C" int64_t
277 _mlir_ciface_verifyMemRefC32(UnrankedMemRefType<impl::complex32> *actual,
278 UnrankedMemRefType<impl::complex32> *expected) {
279 return impl::verifyMemRef(*actual, *expected);
282 extern "C" int64_t
283 _mlir_ciface_verifyMemRefC64(UnrankedMemRefType<impl::complex64> *actual,
284 UnrankedMemRefType<impl::complex64> *expected) {
285 return impl::verifyMemRef(*actual, *expected);
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);
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);
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);
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);
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);
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);
330 // NOLINTEND(*-identifier-naming)