14a966e5dSNicolas Vasilache //===- RunnerUtils.cpp - Utils for MLIR exec on targets with a C++ runtime ===//
2fcfd3a28SNicolas Vasilache //
3fcfd3a28SNicolas Vasilache // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4fcfd3a28SNicolas Vasilache // See https://llvm.org/LICENSE.txt for license information.
5fcfd3a28SNicolas Vasilache // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6fcfd3a28SNicolas Vasilache //
7fcfd3a28SNicolas Vasilache //===----------------------------------------------------------------------===//
8fcfd3a28SNicolas Vasilache //
9e5a85126SKazuaki Ishizaki // This file implements basic functions to debug structured MLIR types at
104a966e5dSNicolas Vasilache // runtime. Entities in this file may not be compatible with targets without a
114a966e5dSNicolas Vasilache // C++ runtime. These may be progressively migrated to CRunnerUtils.cpp over
124a966e5dSNicolas Vasilache // time.
13fcfd3a28SNicolas Vasilache //
14fcfd3a28SNicolas Vasilache //===----------------------------------------------------------------------===//
15fcfd3a28SNicolas Vasilache
16fcfd3a28SNicolas Vasilache #include "mlir/ExecutionEngine/RunnerUtils.h"
17aaea92e1SDenys Shabalin #include <chrono>
18fcfd3a28SNicolas Vasilache
1902b6fb21SMehdi Amini // NOLINTBEGIN(*-identifier-naming)
2002b6fb21SMehdi Amini
_mlir_ciface_printMemrefShapeI8(UnrankedMemRefType<int8_t> * M)21*d4555698SStella Stamenova extern "C" void _mlir_ciface_printMemrefShapeI8(UnrankedMemRefType<int8_t> *M) {
224f4f3f1eSNicolas Vasilache std::cout << "Unranked Memref ";
234f4f3f1eSNicolas Vasilache printMemRefMetaData(std::cout, DynamicMemRefType<int8_t>(*M));
244f4f3f1eSNicolas Vasilache std::cout << "\n";
254f4f3f1eSNicolas Vasilache }
264f4f3f1eSNicolas Vasilache
274f4f3f1eSNicolas Vasilache extern "C" void
_mlir_ciface_printMemrefShapeI32(UnrankedMemRefType<int32_t> * M)28*d4555698SStella Stamenova _mlir_ciface_printMemrefShapeI32(UnrankedMemRefType<int32_t> *M) {
294f4f3f1eSNicolas Vasilache std::cout << "Unranked Memref ";
304f4f3f1eSNicolas Vasilache printMemRefMetaData(std::cout, DynamicMemRefType<int32_t>(*M));
314f4f3f1eSNicolas Vasilache std::cout << "\n";
324f4f3f1eSNicolas Vasilache }
334f4f3f1eSNicolas Vasilache
344f4f3f1eSNicolas Vasilache extern "C" void
_mlir_ciface_printMemrefShapeI64(UnrankedMemRefType<int64_t> * M)35*d4555698SStella Stamenova _mlir_ciface_printMemrefShapeI64(UnrankedMemRefType<int64_t> *M) {
364f4f3f1eSNicolas Vasilache std::cout << "Unranked Memref ";
374f4f3f1eSNicolas Vasilache printMemRefMetaData(std::cout, DynamicMemRefType<int64_t>(*M));
384f4f3f1eSNicolas Vasilache std::cout << "\n";
394f4f3f1eSNicolas Vasilache }
404f4f3f1eSNicolas Vasilache
_mlir_ciface_printMemrefShapeF32(UnrankedMemRefType<float> * M)41*d4555698SStella Stamenova extern "C" void _mlir_ciface_printMemrefShapeF32(UnrankedMemRefType<float> *M) {
424f4f3f1eSNicolas Vasilache std::cout << "Unranked Memref ";
434f4f3f1eSNicolas Vasilache printMemRefMetaData(std::cout, DynamicMemRefType<float>(*M));
444f4f3f1eSNicolas Vasilache std::cout << "\n";
454f4f3f1eSNicolas Vasilache }
464f4f3f1eSNicolas Vasilache
474f4f3f1eSNicolas Vasilache extern "C" void
_mlir_ciface_printMemrefShapeF64(UnrankedMemRefType<double> * M)48*d4555698SStella Stamenova _mlir_ciface_printMemrefShapeF64(UnrankedMemRefType<double> *M) {
494f4f3f1eSNicolas Vasilache std::cout << "Unranked Memref ";
504f4f3f1eSNicolas Vasilache printMemRefMetaData(std::cout, DynamicMemRefType<double>(*M));
514f4f3f1eSNicolas Vasilache std::cout << "\n";
524f4f3f1eSNicolas Vasilache }
534f4f3f1eSNicolas Vasilache
_mlir_ciface_printMemrefVector4x4xf32(StridedMemRefType<Vector2D<4,4,float>,2> * M)54*d4555698SStella Stamenova extern "C" void _mlir_ciface_printMemrefVector4x4xf32(
55fcfd3a28SNicolas Vasilache StridedMemRefType<Vector2D<4, 4, float>, 2> *M) {
56fcfd3a28SNicolas Vasilache impl::printMemRef(*M);
57fcfd3a28SNicolas Vasilache }
58fcfd3a28SNicolas Vasilache
_mlir_ciface_printMemrefI8(UnrankedMemRefType<int8_t> * M)59*d4555698SStella Stamenova extern "C" void _mlir_ciface_printMemrefI8(UnrankedMemRefType<int8_t> *M) {
60222e0e58SChristian Sigg impl::printMemRef(*M);
61fcfd3a28SNicolas Vasilache }
62fcfd3a28SNicolas Vasilache
_mlir_ciface_printMemrefI32(UnrankedMemRefType<int32_t> * M)63*d4555698SStella Stamenova extern "C" void _mlir_ciface_printMemrefI32(UnrankedMemRefType<int32_t> *M) {
64222e0e58SChristian Sigg impl::printMemRef(*M);
65c7380995SValentin Clement }
66c7380995SValentin Clement
_mlir_ciface_printMemrefI64(UnrankedMemRefType<int64_t> * M)67*d4555698SStella Stamenova extern "C" void _mlir_ciface_printMemrefI64(UnrankedMemRefType<int64_t> *M) {
68c6b2c17eSAlexander Belyaev impl::printMemRef(*M);
69c6b2c17eSAlexander Belyaev }
70c6b2c17eSAlexander Belyaev
_mlir_ciface_printMemrefF32(UnrankedMemRefType<float> * M)71*d4555698SStella Stamenova extern "C" void _mlir_ciface_printMemrefF32(UnrankedMemRefType<float> *M) {
72222e0e58SChristian Sigg impl::printMemRef(*M);
73fcfd3a28SNicolas Vasilache }
74fcfd3a28SNicolas Vasilache
_mlir_ciface_printMemrefF64(UnrankedMemRefType<double> * M)75*d4555698SStella Stamenova extern "C" void _mlir_ciface_printMemrefF64(UnrankedMemRefType<double> *M) {
765711eaf6SJakub Lichman impl::printMemRef(*M);
775711eaf6SJakub Lichman }
785711eaf6SJakub Lichman
_mlir_ciface_nanoTime()79*d4555698SStella Stamenova extern "C" int64_t _mlir_ciface_nanoTime() {
80aaea92e1SDenys Shabalin auto now = std::chrono::high_resolution_clock::now();
81aaea92e1SDenys Shabalin auto duration = now.time_since_epoch();
82aaea92e1SDenys Shabalin auto nanoseconds =
83aaea92e1SDenys Shabalin std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
84aaea92e1SDenys Shabalin return nanoseconds.count();
85aaea92e1SDenys Shabalin }
86aaea92e1SDenys Shabalin
printMemrefI32(int64_t rank,void * ptr)87*d4555698SStella Stamenova extern "C" void printMemrefI32(int64_t rank, void *ptr) {
88c7380995SValentin Clement UnrankedMemRefType<int32_t> descriptor = {rank, ptr};
89*d4555698SStella Stamenova _mlir_ciface_printMemrefI32(&descriptor);
90c7380995SValentin Clement }
91c7380995SValentin Clement
printMemrefI64(int64_t rank,void * ptr)92*d4555698SStella Stamenova extern "C" void printMemrefI64(int64_t rank, void *ptr) {
93c6b2c17eSAlexander Belyaev UnrankedMemRefType<int64_t> descriptor = {rank, ptr};
94*d4555698SStella Stamenova _mlir_ciface_printMemrefI64(&descriptor);
95c6b2c17eSAlexander Belyaev }
96c6b2c17eSAlexander Belyaev
printMemrefF32(int64_t rank,void * ptr)97*d4555698SStella Stamenova extern "C" void printMemrefF32(int64_t rank, void *ptr) {
98c7380995SValentin Clement UnrankedMemRefType<float> descriptor = {rank, ptr};
99*d4555698SStella Stamenova _mlir_ciface_printMemrefF32(&descriptor);
100fcfd3a28SNicolas Vasilache }
101fcfd3a28SNicolas Vasilache
printMemrefF64(int64_t rank,void * ptr)102*d4555698SStella Stamenova extern "C" void printMemrefF64(int64_t rank, void *ptr) {
1035711eaf6SJakub Lichman UnrankedMemRefType<double> descriptor = {rank, ptr};
104*d4555698SStella Stamenova _mlir_ciface_printMemrefF64(&descriptor);
1055711eaf6SJakub Lichman }
1065711eaf6SJakub Lichman
printCString(char * str)107*d4555698SStella Stamenova extern "C" void printCString(char *str) { printf("%s", str); }
108215b5ce6SAlexander Belyaev
_mlir_ciface_printMemref0dF32(StridedMemRefType<float,0> * M)109*d4555698SStella Stamenova extern "C" void _mlir_ciface_printMemref0dF32(StridedMemRefType<float, 0> *M) {
110fcfd3a28SNicolas Vasilache impl::printMemRef(*M);
111fcfd3a28SNicolas Vasilache }
_mlir_ciface_printMemref1dF32(StridedMemRefType<float,1> * M)112*d4555698SStella Stamenova extern "C" void _mlir_ciface_printMemref1dF32(StridedMemRefType<float, 1> *M) {
113fcfd3a28SNicolas Vasilache impl::printMemRef(*M);
114fcfd3a28SNicolas Vasilache }
_mlir_ciface_printMemref2dF32(StridedMemRefType<float,2> * M)115*d4555698SStella Stamenova extern "C" void _mlir_ciface_printMemref2dF32(StridedMemRefType<float, 2> *M) {
116fcfd3a28SNicolas Vasilache impl::printMemRef(*M);
117fcfd3a28SNicolas Vasilache }
_mlir_ciface_printMemref3dF32(StridedMemRefType<float,3> * M)118*d4555698SStella Stamenova extern "C" void _mlir_ciface_printMemref3dF32(StridedMemRefType<float, 3> *M) {
119fcfd3a28SNicolas Vasilache impl::printMemRef(*M);
120fcfd3a28SNicolas Vasilache }
_mlir_ciface_printMemref4dF32(StridedMemRefType<float,4> * M)121*d4555698SStella Stamenova extern "C" void _mlir_ciface_printMemref4dF32(StridedMemRefType<float, 4> *M) {
122fcfd3a28SNicolas Vasilache impl::printMemRef(*M);
123fcfd3a28SNicolas Vasilache }
12499f3510bSTobias Gysi
12599f3510bSTobias Gysi extern "C" int64_t
_mlir_ciface_verifyMemRefI32(UnrankedMemRefType<int32_t> * actual,UnrankedMemRefType<int32_t> * expected)12699f3510bSTobias Gysi _mlir_ciface_verifyMemRefI32(UnrankedMemRefType<int32_t> *actual,
12799f3510bSTobias Gysi UnrankedMemRefType<int32_t> *expected) {
12899f3510bSTobias Gysi return impl::verifyMemRef(*actual, *expected);
12999f3510bSTobias Gysi }
13099f3510bSTobias Gysi
13199f3510bSTobias Gysi extern "C" int64_t
_mlir_ciface_verifyMemRefF32(UnrankedMemRefType<float> * actual,UnrankedMemRefType<float> * expected)13299f3510bSTobias Gysi _mlir_ciface_verifyMemRefF32(UnrankedMemRefType<float> *actual,
13399f3510bSTobias Gysi UnrankedMemRefType<float> *expected) {
13499f3510bSTobias Gysi return impl::verifyMemRef(*actual, *expected);
13599f3510bSTobias Gysi }
13699f3510bSTobias Gysi
13799f3510bSTobias Gysi extern "C" int64_t
_mlir_ciface_verifyMemRefF64(UnrankedMemRefType<double> * actual,UnrankedMemRefType<double> * expected)13899f3510bSTobias Gysi _mlir_ciface_verifyMemRefF64(UnrankedMemRefType<double> *actual,
13999f3510bSTobias Gysi UnrankedMemRefType<double> *expected) {
14099f3510bSTobias Gysi return impl::verifyMemRef(*actual, *expected);
14199f3510bSTobias Gysi }
14299f3510bSTobias Gysi
verifyMemRefI32(int64_t rank,void * actualPtr,void * expectedPtr)14399f3510bSTobias Gysi extern "C" int64_t verifyMemRefI32(int64_t rank, void *actualPtr,
14499f3510bSTobias Gysi void *expectedPtr) {
14599f3510bSTobias Gysi UnrankedMemRefType<int32_t> actualDesc = {rank, actualPtr};
14699f3510bSTobias Gysi UnrankedMemRefType<int32_t> expectedDesc = {rank, expectedPtr};
14799f3510bSTobias Gysi return _mlir_ciface_verifyMemRefI32(&actualDesc, &expectedDesc);
14899f3510bSTobias Gysi }
14999f3510bSTobias Gysi
verifyMemRefF32(int64_t rank,void * actualPtr,void * expectedPtr)15099f3510bSTobias Gysi extern "C" int64_t verifyMemRefF32(int64_t rank, void *actualPtr,
15199f3510bSTobias Gysi void *expectedPtr) {
15299f3510bSTobias Gysi UnrankedMemRefType<float> actualDesc = {rank, actualPtr};
15399f3510bSTobias Gysi UnrankedMemRefType<float> expectedDesc = {rank, expectedPtr};
15499f3510bSTobias Gysi return _mlir_ciface_verifyMemRefF32(&actualDesc, &expectedDesc);
15599f3510bSTobias Gysi }
15699f3510bSTobias Gysi
verifyMemRefF64(int64_t rank,void * actualPtr,void * expectedPtr)15799f3510bSTobias Gysi extern "C" int64_t verifyMemRefF64(int64_t rank, void *actualPtr,
15899f3510bSTobias Gysi void *expectedPtr) {
15999f3510bSTobias Gysi UnrankedMemRefType<double> actualDesc = {rank, actualPtr};
16099f3510bSTobias Gysi UnrankedMemRefType<double> expectedDesc = {rank, expectedPtr};
16199f3510bSTobias Gysi return _mlir_ciface_verifyMemRefF64(&actualDesc, &expectedDesc);
16299f3510bSTobias Gysi }
16302b6fb21SMehdi Amini
16402b6fb21SMehdi Amini // NOLINTEND(*-identifier-naming)
165