[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / mlir / lib / ExecutionEngine / RunnerUtils.cpp
blobbbfd3a6b11c2a1bd0ab944aa34378d12d2094647
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_printMemrefI32(UnrankedMemRefType<int32_t> *M) {
85 impl::printMemRef(*M);
88 extern "C" void _mlir_ciface_printMemrefI64(UnrankedMemRefType<int64_t> *M) {
89 impl::printMemRef(*M);
92 extern "C" void _mlir_ciface_printMemrefF32(UnrankedMemRefType<float> *M) {
93 impl::printMemRef(*M);
96 extern "C" void _mlir_ciface_printMemrefF64(UnrankedMemRefType<double> *M) {
97 impl::printMemRef(*M);
100 extern "C" void
101 _mlir_ciface_printMemrefInd(UnrankedMemRefType<impl::index_type> *M) {
102 impl::printMemRef(*M);
105 extern "C" void
106 _mlir_ciface_printMemrefC32(UnrankedMemRefType<impl::complex32> *M) {
107 impl::printMemRef(*M);
110 extern "C" void
111 _mlir_ciface_printMemrefC64(UnrankedMemRefType<impl::complex64> *M) {
112 impl::printMemRef(*M);
115 extern "C" int64_t _mlir_ciface_nanoTime() {
116 auto now = std::chrono::high_resolution_clock::now();
117 auto duration = now.time_since_epoch();
118 auto nanoseconds =
119 std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
120 return nanoseconds.count();
123 extern "C" void printMemrefI32(int64_t rank, void *ptr) {
124 UnrankedMemRefType<int32_t> descriptor = {rank, ptr};
125 _mlir_ciface_printMemrefI32(&descriptor);
128 extern "C" void printMemrefI64(int64_t rank, void *ptr) {
129 UnrankedMemRefType<int64_t> descriptor = {rank, ptr};
130 _mlir_ciface_printMemrefI64(&descriptor);
133 extern "C" void printMemrefF32(int64_t rank, void *ptr) {
134 UnrankedMemRefType<float> descriptor = {rank, ptr};
135 _mlir_ciface_printMemrefF32(&descriptor);
138 extern "C" void printMemrefF64(int64_t rank, void *ptr) {
139 UnrankedMemRefType<double> descriptor = {rank, ptr};
140 _mlir_ciface_printMemrefF64(&descriptor);
143 // Assume index_type is in fact uint64_t.
144 static_assert(std::is_same<impl::index_type, uint64_t>::value,
145 "Expected index_type == uint64_t");
146 extern "C" void printMemrefInd(int64_t rank, void *ptr) {
147 UnrankedMemRefType<impl::index_type> descriptor = {rank, ptr};
148 _mlir_ciface_printMemrefInd(&descriptor);
151 extern "C" void printMemrefC32(int64_t rank, void *ptr) {
152 UnrankedMemRefType<impl::complex32> descriptor = {rank, ptr};
153 _mlir_ciface_printMemrefC32(&descriptor);
156 extern "C" void printMemrefC64(int64_t rank, void *ptr) {
157 UnrankedMemRefType<impl::complex64> descriptor = {rank, ptr};
158 _mlir_ciface_printMemrefC64(&descriptor);
161 extern "C" void _mlir_ciface_printMemref0dF32(StridedMemRefType<float, 0> *M) {
162 impl::printMemRef(*M);
164 extern "C" void _mlir_ciface_printMemref1dF32(StridedMemRefType<float, 1> *M) {
165 impl::printMemRef(*M);
167 extern "C" void _mlir_ciface_printMemref2dF32(StridedMemRefType<float, 2> *M) {
168 impl::printMemRef(*M);
170 extern "C" void _mlir_ciface_printMemref3dF32(StridedMemRefType<float, 3> *M) {
171 impl::printMemRef(*M);
173 extern "C" void _mlir_ciface_printMemref4dF32(StridedMemRefType<float, 4> *M) {
174 impl::printMemRef(*M);
177 extern "C" void _mlir_ciface_printMemref1dI8(StridedMemRefType<int8_t, 1> *M) {
178 impl::printMemRef(*M);
181 extern "C" void
182 _mlir_ciface_printMemref1dI32(StridedMemRefType<int32_t, 1> *M) {
183 impl::printMemRef(*M);
186 extern "C" void
187 _mlir_ciface_printMemref1dI64(StridedMemRefType<int64_t, 1> *M) {
188 impl::printMemRef(*M);
191 extern "C" void _mlir_ciface_printMemref1dF64(StridedMemRefType<double, 1> *M) {
192 impl::printMemRef(*M);
195 extern "C" void
196 _mlir_ciface_printMemref1dInd(StridedMemRefType<impl::index_type, 1> *M) {
197 impl::printMemRef(*M);
200 extern "C" void
201 _mlir_ciface_printMemref1dC32(StridedMemRefType<impl::complex32, 1> *M) {
202 impl::printMemRef(*M);
205 extern "C" void
206 _mlir_ciface_printMemref1dC64(StridedMemRefType<impl::complex64, 1> *M) {
207 impl::printMemRef(*M);
210 extern "C" int64_t
211 _mlir_ciface_verifyMemRefI32(UnrankedMemRefType<int32_t> *actual,
212 UnrankedMemRefType<int32_t> *expected) {
213 return impl::verifyMemRef(*actual, *expected);
216 extern "C" int64_t
217 _mlir_ciface_verifyMemRefF32(UnrankedMemRefType<float> *actual,
218 UnrankedMemRefType<float> *expected) {
219 return impl::verifyMemRef(*actual, *expected);
222 extern "C" int64_t
223 _mlir_ciface_verifyMemRefF64(UnrankedMemRefType<double> *actual,
224 UnrankedMemRefType<double> *expected) {
225 return impl::verifyMemRef(*actual, *expected);
228 extern "C" int64_t
229 _mlir_ciface_verifyMemRefInd(UnrankedMemRefType<impl::index_type> *actual,
230 UnrankedMemRefType<impl::index_type> *expected) {
231 return impl::verifyMemRef(*actual, *expected);
234 extern "C" int64_t
235 _mlir_ciface_verifyMemRefC32(UnrankedMemRefType<impl::complex32> *actual,
236 UnrankedMemRefType<impl::complex32> *expected) {
237 return impl::verifyMemRef(*actual, *expected);
240 extern "C" int64_t
241 _mlir_ciface_verifyMemRefC64(UnrankedMemRefType<impl::complex64> *actual,
242 UnrankedMemRefType<impl::complex64> *expected) {
243 return impl::verifyMemRef(*actual, *expected);
246 extern "C" int64_t verifyMemRefI32(int64_t rank, void *actualPtr,
247 void *expectedPtr) {
248 UnrankedMemRefType<int32_t> actualDesc = {rank, actualPtr};
249 UnrankedMemRefType<int32_t> expectedDesc = {rank, expectedPtr};
250 return _mlir_ciface_verifyMemRefI32(&actualDesc, &expectedDesc);
253 extern "C" int64_t verifyMemRefF32(int64_t rank, void *actualPtr,
254 void *expectedPtr) {
255 UnrankedMemRefType<float> actualDesc = {rank, actualPtr};
256 UnrankedMemRefType<float> expectedDesc = {rank, expectedPtr};
257 return _mlir_ciface_verifyMemRefF32(&actualDesc, &expectedDesc);
260 extern "C" int64_t verifyMemRefF64(int64_t rank, void *actualPtr,
261 void *expectedPtr) {
262 UnrankedMemRefType<double> actualDesc = {rank, actualPtr};
263 UnrankedMemRefType<double> expectedDesc = {rank, expectedPtr};
264 return _mlir_ciface_verifyMemRefF64(&actualDesc, &expectedDesc);
267 extern "C" int64_t verifyMemRefInd(int64_t rank, void *actualPtr,
268 void *expectedPtr) {
269 UnrankedMemRefType<impl::index_type> actualDesc = {rank, actualPtr};
270 UnrankedMemRefType<impl::index_type> expectedDesc = {rank, expectedPtr};
271 return _mlir_ciface_verifyMemRefInd(&actualDesc, &expectedDesc);
274 extern "C" int64_t verifyMemRefC32(int64_t rank, void *actualPtr,
275 void *expectedPtr) {
276 UnrankedMemRefType<impl::complex32> actualDesc = {rank, actualPtr};
277 UnrankedMemRefType<impl::complex32> expectedDesc = {rank, expectedPtr};
278 return _mlir_ciface_verifyMemRefC32(&actualDesc, &expectedDesc);
281 extern "C" int64_t verifyMemRefC64(int64_t rank, void *actualPtr,
282 void *expectedPtr) {
283 UnrankedMemRefType<impl::complex64> actualDesc = {rank, actualPtr};
284 UnrankedMemRefType<impl::complex64> expectedDesc = {rank, expectedPtr};
285 return _mlir_ciface_verifyMemRefC64(&actualDesc, &expectedDesc);
288 // NOLINTEND(*-identifier-naming)