MLIR  15.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 
57 }
58 
61 }
62 
65 }
66 
69 }
70 
73 }
74 
77 }
78 
79 extern "C" int64_t _mlir_ciface_nanoTime() {
80  auto now = std::chrono::high_resolution_clock::now();
81  auto duration = now.time_since_epoch();
82  auto nanoseconds =
83  std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
84  return nanoseconds.count();
85 }
86 
87 extern "C" void printMemrefI32(int64_t rank, void *ptr) {
88  UnrankedMemRefType<int32_t> descriptor = {rank, ptr};
89  _mlir_ciface_printMemrefI32(&descriptor);
90 }
91 
92 extern "C" void printMemrefI64(int64_t rank, void *ptr) {
93  UnrankedMemRefType<int64_t> descriptor = {rank, ptr};
94  _mlir_ciface_printMemrefI64(&descriptor);
95 }
96 
97 extern "C" void printMemrefF32(int64_t rank, void *ptr) {
98  UnrankedMemRefType<float> descriptor = {rank, ptr};
99  _mlir_ciface_printMemrefF32(&descriptor);
100 }
101 
102 extern "C" void printMemrefF64(int64_t rank, void *ptr) {
103  UnrankedMemRefType<double> descriptor = {rank, ptr};
104  _mlir_ciface_printMemrefF64(&descriptor);
105 }
106 
107 extern "C" void printCString(char *str) { printf("%s", str); }
108 
110  impl::printMemRef(*M);
111 }
113  impl::printMemRef(*M);
114 }
116  impl::printMemRef(*M);
117 }
119  impl::printMemRef(*M);
120 }
122  impl::printMemRef(*M);
123 }
124 
125 extern "C" int64_t
127  UnrankedMemRefType<int32_t> *expected) {
128  return impl::verifyMemRef(*actual, *expected);
129 }
130 
131 extern "C" int64_t
133  UnrankedMemRefType<float> *expected) {
134  return impl::verifyMemRef(*actual, *expected);
135 }
136 
137 extern "C" int64_t
139  UnrankedMemRefType<double> *expected) {
140  return impl::verifyMemRef(*actual, *expected);
141 }
142 
143 extern "C" int64_t verifyMemRefI32(int64_t rank, void *actualPtr,
144  void *expectedPtr) {
145  UnrankedMemRefType<int32_t> actualDesc = {rank, actualPtr};
146  UnrankedMemRefType<int32_t> expectedDesc = {rank, expectedPtr};
147  return _mlir_ciface_verifyMemRefI32(&actualDesc, &expectedDesc);
148 }
149 
150 extern "C" int64_t verifyMemRefF32(int64_t rank, void *actualPtr,
151  void *expectedPtr) {
152  UnrankedMemRefType<float> actualDesc = {rank, actualPtr};
153  UnrankedMemRefType<float> expectedDesc = {rank, expectedPtr};
154  return _mlir_ciface_verifyMemRefF32(&actualDesc, &expectedDesc);
155 }
156 
157 extern "C" int64_t verifyMemRefF64(int64_t rank, void *actualPtr,
158  void *expectedPtr) {
159  UnrankedMemRefType<double> actualDesc = {rank, actualPtr};
160  UnrankedMemRefType<double> expectedDesc = {rank, expectedPtr};
161  return _mlir_ciface_verifyMemRefF64(&actualDesc, &expectedDesc);
162 }
163 
164 // NOLINTEND(*-identifier-naming)
void _mlir_ciface_printMemref1dF32(StridedMemRefType< float, 1 > *M)
void printMemRefMetaData(StreamType &os, const DynamicMemRefType< T > &v)
Definition: RunnerUtils.h:41
void _mlir_ciface_printMemrefShapeI64(UnrankedMemRefType< int64_t > *M)
Definition: RunnerUtils.cpp:35
void _mlir_ciface_printMemrefShapeF64(UnrankedMemRefType< double > *M)
Definition: RunnerUtils.cpp:48
void _mlir_ciface_printMemref0dF32(StridedMemRefType< float, 0 > *M)
int64_t _mlir_ciface_nanoTime()
Definition: RunnerUtils.cpp:79
void _mlir_ciface_printMemrefI64(UnrankedMemRefType< int64_t > *M)
Definition: RunnerUtils.cpp:67
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:310
void _mlir_ciface_printMemrefF32(UnrankedMemRefType< float > *M)
Definition: RunnerUtils.cpp:71
void _mlir_ciface_printMemref4dF32(StridedMemRefType< float, 4 > *M)
void printMemrefI64(int64_t rank, void *ptr)
Definition: RunnerUtils.cpp:92
int64_t _mlir_ciface_verifyMemRefF32(UnrankedMemRefType< float > *actual, UnrankedMemRefType< float > *expected)
void _mlir_ciface_printMemrefF64(UnrankedMemRefType< double > *M)
Definition: RunnerUtils.cpp:75
void _mlir_ciface_printMemrefI32(UnrankedMemRefType< int32_t > *M)
Definition: RunnerUtils.cpp:63
int64_t _mlir_ciface_verifyMemRefF64(UnrankedMemRefType< double > *actual, UnrankedMemRefType< double > *expected)
void _mlir_ciface_printMemrefI8(UnrankedMemRefType< int8_t > *M)
Definition: RunnerUtils.cpp:59
void _mlir_ciface_printMemrefShapeI8(UnrankedMemRefType< int8_t > *M)
Definition: RunnerUtils.cpp:21
void printMemrefI32(int64_t rank, void *ptr)
Definition: RunnerUtils.cpp:87
void _mlir_ciface_printMemrefShapeF32(UnrankedMemRefType< float > *M)
Definition: RunnerUtils.cpp:41
void _mlir_ciface_printMemrefVector4x4xf32(StridedMemRefType< Vector2D< 4, 4, float >, 2 > *M)
Definition: RunnerUtils.cpp:54
void printMemrefF64(int64_t rank, void *ptr)
int64_t verifyMemRefF32(int64_t rank, void *actualPtr, void *expectedPtr)
void _mlir_ciface_printMemrefShapeI32(UnrankedMemRefType< int32_t > *M)
Definition: RunnerUtils.cpp:28
void _mlir_ciface_printMemref2dF32(StridedMemRefType< float, 2 > *M)
void printMemRef(const DynamicMemRefType< T > &m)
Definition: RunnerUtils.h:208
void _mlir_ciface_printMemref3dF32(StridedMemRefType< float, 3 > *M)
void printCString(char *str)
int64_t _mlir_ciface_verifyMemRefI32(UnrankedMemRefType< int32_t > *actual, UnrankedMemRefType< int32_t > *expected)
StridedMemRef descriptor type with static rank.
Definition: CRunnerUtils.h:130
int64_t verifyMemRefI32(int64_t rank, void *actualPtr, void *expectedPtr)
void printMemrefF32(int64_t rank, void *ptr)
Definition: RunnerUtils.cpp:97
int64_t verifyMemRefF64(int64_t rank, void *actualPtr, void *expectedPtr)