forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunnerUtils.cpp
100 lines (89 loc) · 3.24 KB
/
RunnerUtils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//===- RunnerUtils.cpp - Utils for MLIR CPU execution ---------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Utilities for interfacing MLIR types with C code as well as printing,
// debugging etc.
//
//===----------------------------------------------------------------------===//
#include "mlir/ExecutionEngine/RunnerUtils.h"
#include <cinttypes>
#include <cstdio>
extern "C" void _mlir_ciface_print_memref_vector_4x4xf32(
StridedMemRefType<Vector2D<4, 4, float>, 2> *M) {
impl::printMemRef(*M);
}
#define MEMREF_CASE(TYPE, RANK) \
case RANK: \
impl::printMemRef(*(static_cast<StridedMemRefType<TYPE, RANK> *>(ptr))); \
break
extern "C" void _mlir_ciface_print_memref_i8(UnrankedMemRefType<int8_t> *M) {
printUnrankedMemRefMetaData(std::cout, *M);
int rank = M->rank;
void *ptr = M->descriptor;
switch (rank) {
MEMREF_CASE(int8_t, 0);
MEMREF_CASE(int8_t, 1);
MEMREF_CASE(int8_t, 2);
MEMREF_CASE(int8_t, 3);
MEMREF_CASE(int8_t, 4);
default:
assert(0 && "Unsupported rank to print");
}
}
extern "C" void _mlir_ciface_print_memref_f32(UnrankedMemRefType<float> *M) {
printUnrankedMemRefMetaData(std::cout, *M);
int rank = M->rank;
void *ptr = M->descriptor;
switch (rank) {
MEMREF_CASE(float, 0);
MEMREF_CASE(float, 1);
MEMREF_CASE(float, 2);
MEMREF_CASE(float, 3);
MEMREF_CASE(float, 4);
default:
assert(0 && "Unsupported rank to print");
}
}
extern "C" void print_memref_f32(int64_t rank, void *ptr) {
UnrankedMemRefType<float> descriptor;
descriptor.rank = rank;
descriptor.descriptor = ptr;
_mlir_ciface_print_memref_f32(&descriptor);
}
extern "C" void
_mlir_ciface_print_memref_0d_f32(StridedMemRefType<float, 0> *M) {
impl::printMemRef(*M);
}
extern "C" void
_mlir_ciface_print_memref_1d_f32(StridedMemRefType<float, 1> *M) {
impl::printMemRef(*M);
}
extern "C" void
_mlir_ciface_print_memref_2d_f32(StridedMemRefType<float, 2> *M) {
impl::printMemRef(*M);
}
extern "C" void
_mlir_ciface_print_memref_3d_f32(StridedMemRefType<float, 3> *M) {
impl::printMemRef(*M);
}
extern "C" void
_mlir_ciface_print_memref_4d_f32(StridedMemRefType<float, 4> *M) {
impl::printMemRef(*M);
}
// Small runtime support "lib" for vector.print lowering.
// By providing elementary printing methods only, this
// library can remain fully unaware of low-level implementation
// details of our vectors. Also useful for direct LLVM IR output.
extern "C" void print_i32(int32_t i) { fprintf(stdout, "%" PRId32, i); }
extern "C" void print_i64(int64_t l) { fprintf(stdout, "%" PRId64, l); }
extern "C" void print_f32(float f) { fprintf(stdout, "%g", f); }
extern "C" void print_f64(double d) { fprintf(stdout, "%lg", d); }
extern "C" void print_open() { fputs("( ", stdout); }
extern "C" void print_close() { fputs(" )", stdout); }
extern "C" void print_comma() { fputs(", ", stdout); }
extern "C" void print_newline() { fputc('\n', stdout); }