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 16 #include "mlir/ExecutionEngine/RunnerUtils.h" 17 18 #ifndef _WIN32 19 #include <sys/time.h> 20 #endif // _WIN32 21 22 extern "C" void _mlir_ciface_print_memref_vector_4x4xf32( 23 StridedMemRefType<Vector2D<4, 4, float>, 2> *M) { 24 impl::printMemRef(*M); 25 } 26 27 extern "C" void _mlir_ciface_print_memref_i8(UnrankedMemRefType<int8_t> *M) { 28 impl::printMemRef(*M); 29 } 30 31 extern "C" void _mlir_ciface_print_memref_i32(UnrankedMemRefType<int32_t> *M) { 32 impl::printMemRef(*M); 33 } 34 35 extern "C" void _mlir_ciface_print_memref_f32(UnrankedMemRefType<float> *M) { 36 impl::printMemRef(*M); 37 } 38 39 extern "C" void print_memref_i32(int64_t rank, void *ptr) { 40 UnrankedMemRefType<int32_t> descriptor = {rank, ptr}; 41 _mlir_ciface_print_memref_i32(&descriptor); 42 } 43 44 extern "C" void print_memref_f32(int64_t rank, void *ptr) { 45 UnrankedMemRefType<float> descriptor = {rank, ptr}; 46 _mlir_ciface_print_memref_f32(&descriptor); 47 } 48 49 extern "C" void 50 _mlir_ciface_print_memref_0d_f32(StridedMemRefType<float, 0> *M) { 51 impl::printMemRef(*M); 52 } 53 extern "C" void 54 _mlir_ciface_print_memref_1d_f32(StridedMemRefType<float, 1> *M) { 55 impl::printMemRef(*M); 56 } 57 extern "C" void 58 _mlir_ciface_print_memref_2d_f32(StridedMemRefType<float, 2> *M) { 59 impl::printMemRef(*M); 60 } 61 extern "C" void 62 _mlir_ciface_print_memref_3d_f32(StridedMemRefType<float, 3> *M) { 63 impl::printMemRef(*M); 64 } 65 extern "C" void 66 _mlir_ciface_print_memref_4d_f32(StridedMemRefType<float, 4> *M) { 67 impl::printMemRef(*M); 68 } 69 70 /// Prints GFLOPS rating. 71 extern "C" void print_flops(double flops) { 72 fprintf(stderr, "%lf GFLOPS\n", flops / 1.0E9); 73 } 74 75 /// Returns the number of seconds since Epoch 1970-01-01 00:00:00 +0000 (UTC). 76 extern "C" double rtclock() { 77 #ifndef _WIN32 78 struct timeval tp; 79 int stat = gettimeofday(&tp, NULL); 80 if (stat != 0) 81 fprintf(stderr, "Error returning time from gettimeofday: %d\n", stat); 82 return (tp.tv_sec + tp.tv_usec * 1.0e-6); 83 #else 84 fprintf(stderr, "Timing utility not implemented on Windows\n"); 85 return 0.0; 86 #endif // _WIN32 87 } 88