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 imlpements 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 
16 #include "mlir/ExecutionEngine/RunnerUtils.h"
17 
18 extern "C" void _mlir_ciface_print_memref_vector_4x4xf32(
19     StridedMemRefType<Vector2D<4, 4, float>, 2> *M) {
20   impl::printMemRef(*M);
21 }
22 
23 #define MEMREF_CASE(TYPE, RANK)                                                \
24   case RANK:                                                                   \
25     impl::printMemRef(*(static_cast<StridedMemRefType<TYPE, RANK> *>(ptr)));   \
26     break
27 
28 extern "C" void _mlir_ciface_print_memref_i8(UnrankedMemRefType<int8_t> *M) {
29   printUnrankedMemRefMetaData(std::cout, *M);
30   int64_t rank = M->rank;
31   void *ptr = M->descriptor;
32 
33   switch (rank) {
34     MEMREF_CASE(int8_t, 0);
35     MEMREF_CASE(int8_t, 1);
36     MEMREF_CASE(int8_t, 2);
37     MEMREF_CASE(int8_t, 3);
38     MEMREF_CASE(int8_t, 4);
39   default:
40     assert(0 && "Unsupported rank to print");
41   }
42 }
43 
44 extern "C" void _mlir_ciface_print_memref_i32(UnrankedMemRefType<int32_t> *M) {
45   printUnrankedMemRefMetaData(std::cout, *M);
46   int64_t rank = M->rank;
47   void *ptr = M->descriptor;
48 
49   switch (rank) {
50     MEMREF_CASE(int32_t, 0);
51     MEMREF_CASE(int32_t, 1);
52     MEMREF_CASE(int32_t, 2);
53     MEMREF_CASE(int32_t, 3);
54     MEMREF_CASE(int32_t, 4);
55   default:
56     assert(0 && "Unsupported rank to print");
57   }
58 }
59 
60 extern "C" void _mlir_ciface_print_memref_f32(UnrankedMemRefType<float> *M) {
61   printUnrankedMemRefMetaData(std::cout, *M);
62   int64_t rank = M->rank;
63   void *ptr = M->descriptor;
64 
65   switch (rank) {
66     MEMREF_CASE(float, 0);
67     MEMREF_CASE(float, 1);
68     MEMREF_CASE(float, 2);
69     MEMREF_CASE(float, 3);
70     MEMREF_CASE(float, 4);
71   default:
72     assert(0 && "Unsupported rank to print");
73   }
74 }
75 
76 extern "C" void print_memref_i32(int64_t rank, void *ptr) {
77   UnrankedMemRefType<int32_t> descriptor = {rank, ptr};
78   _mlir_ciface_print_memref_i32(&descriptor);
79 }
80 
81 extern "C" void print_memref_f32(int64_t rank, void *ptr) {
82   UnrankedMemRefType<float> descriptor = {rank, ptr};
83   _mlir_ciface_print_memref_f32(&descriptor);
84 }
85 
86 extern "C" void
87 _mlir_ciface_print_memref_0d_f32(StridedMemRefType<float, 0> *M) {
88   impl::printMemRef(*M);
89 }
90 extern "C" void
91 _mlir_ciface_print_memref_1d_f32(StridedMemRefType<float, 1> *M) {
92   impl::printMemRef(*M);
93 }
94 extern "C" void
95 _mlir_ciface_print_memref_2d_f32(StridedMemRefType<float, 2> *M) {
96   impl::printMemRef(*M);
97 }
98 extern "C" void
99 _mlir_ciface_print_memref_3d_f32(StridedMemRefType<float, 3> *M) {
100   impl::printMemRef(*M);
101 }
102 extern "C" void
103 _mlir_ciface_print_memref_4d_f32(StridedMemRefType<float, 4> *M) {
104   impl::printMemRef(*M);
105 }
106