Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DIP] Add benchmark for Buddy & OpenCV rotation operation. #63

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove duplicate enum class for angle type.
taiqzheng committed May 31, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit fb143272212f9e1b86101f65ee0a13c476872192
25 changes: 11 additions & 14 deletions benchmarks/ImageProcessing/BuddyRotate2DBenchmark.cpp
Original file line number Diff line number Diff line change
@@ -36,11 +36,8 @@ float BuddyRotate2DAngle;
// Define sizes of input.
intptr_t sizesInputBuddyRotate2D[2];

// Declare Angle option supported.
enum AngleOption { ANGLE_DEGREE, ANGLE_RADIAN };

// Define Angle option selected.
AngleOption AngleType;
dip::ANGLE_TYPE AngleType;

void initializeBuddyRotate2D(char **argv) {
inputImageBuddyRotate2D = imread(argv[1], IMREAD_GRAYSCALE);
@@ -49,9 +46,9 @@ void initializeBuddyRotate2D(char **argv) {
sizesInputBuddyRotate2D[1] = inputImageBuddyRotate2D.cols;

if (static_cast<string>(argv[2]) == "DEGREE") {
AngleType = ANGLE_DEGREE;
AngleType = dip::ANGLE_TYPE::DEGREE;
} else {
AngleType = ANGLE_RADIAN;
AngleType = dip::ANGLE_TYPE::RADIAN;
}

std::string argAngle = argv[3];
@@ -62,7 +59,7 @@ void initializeBuddyRotate2D(char **argv) {
}
}

static void Buddy_Rotate2D_ANGLE_DEGREE(benchmark::State &state) {
static void Buddy_Rotate2D_DEGREE(benchmark::State &state) {
// Define the MemRef descriptor for input.
Img<float, 2> inputBuddyRotate2D(inputImageBuddyRotate2D);

@@ -75,7 +72,7 @@ static void Buddy_Rotate2D_ANGLE_DEGREE(benchmark::State &state) {
}
}

static void Buddy_Rotate2D_ANGLE_RADIAN(benchmark::State &state) {
static void Buddy_Rotate2D_RADIAN(benchmark::State &state) {
// Define the MemRef descriptor for input.
Img<float, 2> inputBuddyRotate2D(inputImageBuddyRotate2D);

@@ -90,12 +87,12 @@ static void Buddy_Rotate2D_ANGLE_RADIAN(benchmark::State &state) {

// Register benchmarking function.
void registerBenchmarkBuddyRotate2D() {
if (AngleType == ANGLE_DEGREE) {
BENCHMARK(Buddy_Rotate2D_ANGLE_DEGREE)
if (AngleType == dip::ANGLE_TYPE::DEGREE) {
BENCHMARK(Buddy_Rotate2D_DEGREE)
->Arg(1)
->Unit(benchmark::kMillisecond);
} else {
BENCHMARK(Buddy_Rotate2D_ANGLE_RADIAN)
BENCHMARK(Buddy_Rotate2D_RADIAN)
->Arg(1)
->Unit(benchmark::kMillisecond);
}
@@ -106,8 +103,8 @@ void generateResultBuddyRotate2D() {
// Define the MemRef descriptor for input.
Img<float, 2> input(inputImageBuddyRotate2D);
MemRef<float, 2> output(sizesInputBuddyRotate2D);
// Run the resize 2D operation.
if (AngleType == ANGLE_DEGREE) {
// Run the rotate 2D operation.
if (AngleType == dip::ANGLE_TYPE::DEGREE) {
// Call the MLIR Rotate2D function.
output = dip::Rotate2D(&input, BuddyRotate2DAngle,
dip::ANGLE_TYPE::DEGREE);
@@ -117,7 +114,7 @@ void generateResultBuddyRotate2D() {
dip::ANGLE_TYPE::RADIAN);
}

// Define a cv::Mat with the output of the resize operation.
// Define a cv::Mat with the output of the rotate operation.
Mat outputImage(output.getSizes()[0], output.getSizes()[1], CV_32FC1,
output.getData());

20 changes: 9 additions & 11 deletions benchmarks/ImageProcessing/OpenCVRotate2DBenchmark.cpp
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@

#include <benchmark/benchmark.h>
#include <opencv2/opencv.hpp>
#include <buddy/DIP/DIP.h>

using namespace cv;
using namespace std;
@@ -34,11 +35,8 @@ int OpenCVRotate2DAngle;
intptr_t sizesInputOpenCVRotate2D[2];
cv::Size sizesOutputOpenCVRotate2D;

// Declare Angle option supported.
enum AngleOption { ANGLE_DEGREE, ANGLE_RADIAN };

// Define Angle option selected.
AngleOption OpenCVAngleType;
dip::ANGLE_TYPE OpenCVAngleType;

// Define OpenCV Rotate option.
cv::RotateFlags RotateFlag = cv::ROTATE_90_CLOCKWISE;
@@ -53,9 +51,9 @@ void initializeOpenCVRotate2D(char **argv) {
sizesInputOpenCVRotate2D[1] = inputImageOpenCVRotate2D.cols;

if (static_cast<string>(argv[2]) == "DEGREE") {
OpenCVAngleType = ANGLE_DEGREE;
OpenCVAngleType = dip::ANGLE_TYPE::DEGREE;
} else {
OpenCVAngleType = ANGLE_RADIAN;
OpenCVAngleType = dip::ANGLE_TYPE::RADIAN;
}

std::string argAngle = argv[3];
@@ -77,7 +75,7 @@ void initializeOpenCVRotate2D(char **argv) {
}

// Benchmarking function.
static void OpenCV_Rotate2D_ANGLE_DEGREE(benchmark::State &state) {
static void OpenCV_Rotate2D_DEGREE(benchmark::State &state) {
for (auto _ : state) {
for (int i = 0; i < state.range(0); ++i) {
cv::rotate(inputImageOpenCVRotate2D, outputImageOpenCVRotate2D, RotateFlag);
@@ -87,17 +85,17 @@ static void OpenCV_Rotate2D_ANGLE_DEGREE(benchmark::State &state) {

// Register benchmarking function.
void registerBenchmarkOpenCVRotate2D() {
if (OpenCVAngleType == ANGLE_DEGREE && OpenCVRunRotate == true) {
BENCHMARK(OpenCV_Rotate2D_ANGLE_DEGREE)
if (OpenCVAngleType == dip::ANGLE_TYPE::DEGREE && OpenCVRunRotate == true) {
BENCHMARK(OpenCV_Rotate2D_DEGREE)
->Arg(1)
->Unit(benchmark::kMillisecond);
}
}

// Generate result image.
void generateResultOpenCVRotate2D() {
// Run the resize 2D operation.
if (OpenCVAngleType == ANGLE_DEGREE && OpenCVRunRotate == true) {
// Run the rotate 2D operation.
if (OpenCVAngleType == dip::ANGLE_TYPE::DEGREE && OpenCVRunRotate == true) {
cv::rotate(inputImageOpenCVRotate2D, outputImageOpenCVRotate2D, OpenCVRotate2DAngle);

// Choose a PNG compression level