64 lines
2.0 KiB
C++
64 lines
2.0 KiB
C++
#include <iostream>
|
|
|
|
#include "hls_qcnn_accel.h"
|
|
#include "hls_qcnn_tb_data.h"
|
|
|
|
static unsigned int image_words[HLS_QCNN_IMAGE_WORDS];
|
|
static short weights[HLS_QCNN_WEIGHT_COUNT];
|
|
static short buf0[HLS_QCNN_FEATURE_BUFFER_SIZE];
|
|
static short buf1[HLS_QCNN_FEATURE_BUFFER_SIZE];
|
|
static int logits[HLS_QCNN_NUM_CLASSES];
|
|
|
|
int main() {
|
|
std::cout << "HLS-QCNN test image: " << HLS_QCNN_TB_IMAGE_PATH << std::endl;
|
|
for (int i = 0; i < HLS_QCNN_IMAGE_WORDS; i++) {
|
|
image_words[i] = hls_qcnn_tb_image_words[i];
|
|
}
|
|
for (int i = 0; i < HLS_QCNN_WEIGHT_COUNT; i++) {
|
|
weights[i] = hls_qcnn_tb_weights[i];
|
|
}
|
|
for (int i = 0; i < HLS_QCNN_FEATURE_BUFFER_SIZE; i++) {
|
|
buf0[i] = 0;
|
|
buf1[i] = 0;
|
|
}
|
|
for (int i = 0; i < HLS_QCNN_NUM_CLASSES; i++) {
|
|
logits[i] = 0;
|
|
}
|
|
|
|
hls_qcnn_accel(image_words, weights, buf0, buf1, logits);
|
|
|
|
int best_class = 0;
|
|
int best_logit = logits[0];
|
|
int golden_class = 0;
|
|
int golden_best = hls_qcnn_tb_golden_logits[0];
|
|
bool exact = true;
|
|
|
|
for (int cls = 0; cls < HLS_QCNN_NUM_CLASSES; cls++) {
|
|
std::cout << "logit[" << cls << "]=" << logits[cls]
|
|
<< " golden=" << hls_qcnn_tb_golden_logits[cls] << std::endl;
|
|
if (logits[cls] != hls_qcnn_tb_golden_logits[cls]) {
|
|
exact = false;
|
|
}
|
|
if (logits[cls] > best_logit) {
|
|
best_logit = logits[cls];
|
|
best_class = cls;
|
|
}
|
|
if (hls_qcnn_tb_golden_logits[cls] > golden_best) {
|
|
golden_best = hls_qcnn_tb_golden_logits[cls];
|
|
golden_class = cls;
|
|
}
|
|
}
|
|
|
|
std::cout << "predicted_class=" << best_class << std::endl;
|
|
std::cout << "golden_class=" << golden_class << std::endl;
|
|
if (best_class != golden_class) {
|
|
std::cerr << "ERROR: predicted class does not match golden class" << std::endl;
|
|
return 1;
|
|
}
|
|
if (!exact) {
|
|
std::cerr << "ERROR: logits do not exactly match golden logits" << std::endl;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|