forked from Xilinx/mlir-aie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
88 lines (75 loc) · 2.92 KB
/
test.cpp
File metadata and controls
88 lines (75 loc) · 2.92 KB
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
//===- test.cpp -------------------------------------------------*- C++ -*-===//
//
// This file is licensed 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
//
// Copyright (C) 2023, Advanced Micro Devices, Inc.
//
//===----------------------------------------------------------------------===//
#include "xrt_test_wrapper.h"
#include <cstdint>
//*****************************************************************************
// Modify this section to customize buffer datatypes, initialization functions,
// and verify function. The other place to reconfigure your design is the
// Makefile.
//*****************************************************************************
#ifndef DATATYPES_USING_DEFINED
#define DATATYPES_USING_DEFINED
// ------------------------------------------------------
// Configure this to match your buffer data type
// ------------------------------------------------------
#if INT_BIT_WIDTH == 16
using DATATYPE_IN1 = std::int16_t;
using DATATYPE_OUT = std::int16_t;
#else
using DATATYPE_IN1 = std::int32_t;
using DATATYPE_OUT = std::int32_t;
#endif
using DATATYPE_IN2 = std::int32_t;
#endif
// Initialize Input buffer 1
void initialize_bufIn1(DATATYPE_IN1 *bufIn1, int SIZE) {
for (int i = 0; i < SIZE; i++)
bufIn1[i] = i + 1;
}
// Initialize Input buffer 2
void initialize_bufIn2(DATATYPE_IN2 *bufIn2, int SIZE) {
bufIn2[0] = 3; // scaleFactor
}
// Initialize Output buffer
void initialize_bufOut(DATATYPE_OUT *bufOut, int SIZE) {
memset(bufOut, 0, SIZE);
}
// Functional correctness verifyer
int verify_vector_scalar_mul(DATATYPE_IN1 *bufIn1, DATATYPE_IN2 *bufIn2,
DATATYPE_OUT *bufOut, int SIZE, int verbosity) {
int errors = 0;
for (int i = 0; i < SIZE; i++) {
int32_t ref = bufIn1[i] * bufIn2[0];
int32_t test = bufOut[i];
if (test != ref) {
if (verbosity >= 1)
std::cout << "Error in output " << test << " != " << ref << std::endl;
errors++;
} else {
if (verbosity >= 1)
std::cout << "Correct output " << test << " == " << ref << std::endl;
}
}
return errors;
}
//*****************************************************************************
// Should not need to modify below section
//*****************************************************************************
int main(int argc, const char *argv[]) {
constexpr int IN1_VOLUME = IN1_SIZE / sizeof(DATATYPE_IN1);
constexpr int IN2_VOLUME = IN2_SIZE / sizeof(DATATYPE_IN2);
constexpr int OUT_VOLUME = OUT_SIZE / sizeof(DATATYPE_OUT);
args myargs = parse_args(argc, argv);
int res = setup_and_run_aie<DATATYPE_IN1, DATATYPE_IN2, DATATYPE_OUT,
initialize_bufIn1, initialize_bufIn2,
initialize_bufOut, verify_vector_scalar_mul>(
IN1_VOLUME, IN2_VOLUME, OUT_VOLUME, myargs, true);
return res;
}