Skip to content

Commit

Permalink
WIP: Fix compilation error for MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
Fixstars-iizuka committed Oct 6, 2021
1 parent 7cd5493 commit 6cd2d55
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmake/ImportIonBB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ macro(ion_import_building_block)

add_library(ion-bb SHARED ${CMAKE_BINARY_DIR}/ion-bb.cc)
target_include_directories(ion-bb PUBLIC ${PROJECT_SOURCE_DIR}/include ${ION_BB_INCLUDE_DIRS})
target_link_libraries(ion-bb PUBLIC Halide::Halide Halide::Runtime)
target_link_libraries(ion-bb PUBLIC ion-core ${ION_BB_LIBRARIES})
install(TARGETS ion-bb DESTINATION lib)
endmacro()
1 change: 0 additions & 1 deletion include/ion-bb-dnn/rt_dnndk.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <dlfcn.h>
#include <fstream>
#include <iomanip>
#include <iostream>
Expand Down
8 changes: 7 additions & 1 deletion include/ion-bb-dnn/rt_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
#define ION_BB_DNN_UTIL_H

#include <algorithm>
#include <dlfcn.h>
#include <map>
#include <stdexcept>
#include <string>
#include <vector>

#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif


#include <opencv2/core.hpp>

namespace ion {
Expand Down
5 changes: 4 additions & 1 deletion include/ion-bb-image-io/bb.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#define ION_BB_IMAGE_IO_BB_H

#include <ion/ion.h>
#ifndef _WIN32
#include <linux/videodev2.h>
#endif

#include "sole.hpp"

Expand Down Expand Up @@ -546,11 +548,12 @@ class ImageSaver : public ion::BuildingBlock<ImageSaver> {
} // namespace image_io
} // namespace bb
} // namespace ion

#ifndef _WIN32
ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::IMX219, image_io_imx219);
ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::D435, image_io_d435);
ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::Camera, image_io_camera);
ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::GenericV4L2Bayer, image_io_generic_v4l2_bayer);
#endif
ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::CameraSimulation, image_io_camera_simulation);
ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::GUIDisplay, image_io_gui_display);
ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::FBDisplay, image_io_fb_display);
Expand Down
16 changes: 8 additions & 8 deletions include/ion-bb-image-processing/bb.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Luminance {
static Halide::Expr calc(Method method, Halide::Expr r, Halide::Expr g, Halide::Expr b) {
switch (method) {
case Method::Max:
return Halide::max(r, g, b);
return (Halide::max)(r, g, b);
case Method::Average:
return (r + g + b) / 3;
case Method::SimpleY:
Expand Down Expand Up @@ -171,7 +171,7 @@ const std::map<std::string, BoundaryConditions::Method> BoundaryConditions::enum
Halide::Expr lut_interpolation_float(Halide::Func lut, Halide::Expr value, int32_t lut_size) {
Halide::Expr index0, index1, diff, coef;
index0 = Halide::cast(Halide::Int(32), Halide::floor(value * lut_size));
index1 = Halide::min(index0 + 1, lut_size);
index1 = (Halide::min)(index0 + 1, lut_size);
diff = lut(index1) - lut(index0);
coef = value - index0;
return lut(index0) + coef * diff;
Expand Down Expand Up @@ -1010,8 +1010,8 @@ class LensDistortionCorrectionLUT : public BuildingBlock<X> {
Halide::Expr max_x, max_y, dx, dy, r2, r_coef;
Halide::Expr map_x, map_y, x0, y0, x1, y1, x_coef, y_coef;

max_x = Halide::max(cx, Halide::cast<float>(width) - cx);
max_y = Halide::max(cy, Halide::cast<float>(height) - cy);
max_x = (Halide::max)(cx, Halide::cast<float>(width) - cx);
max_y = (Halide::max)(cy, Halide::cast<float>(height) - cy);
dx = x - cx;
dy = y - cy;
r2 = (dx * dx + dy * dy) / (max_x * max_x + max_y * max_y);
Expand Down Expand Up @@ -1305,8 +1305,8 @@ class ResizeAreaAverage : public BuildingBlock<X> {
base_y = Halide::cast<int32_t>(Halide::floor(start_y));

sum(x, y, Halide::_) += input_wrapper(base_x + r.x, base_y + r.y, Halide::_) *
(Halide::clamp(end_x - (base_x + r.x), 0.f, 1.f) - Halide::max(start_x - (base_x + r.x), 0.f)) *
(Halide::clamp(end_y - (base_y + r.y), 0.f, 1.f) - Halide::max(start_y - (base_y + r.y), 0.f));
(Halide::clamp(end_x - (base_x + r.x), 0.f, 1.f) - (Halide::max)(start_x - (base_x + r.x), 0.f)) *
(Halide::clamp(end_y - (base_y + r.y), 0.f, 1.f) - (Halide::max)(start_y - (base_y + r.y), 0.f));

output(x, y, Halide::_) = sum(x, y, Halide::_) / (pix_size * pix_size);
}
Expand Down Expand Up @@ -1843,8 +1843,8 @@ class ColorSpaceConverterRGBToHSV : public ion::BuildingBlock<ColorSpaceConverte
Expr g = input(x, y, 1);
Expr b = input(x, y, 2);

Expr minv = min(r, min(g, b));
Expr maxv = max(r, max(g, b));
Expr minv = (Halide::min)(r, (Halide::min)(g, b));
Expr maxv = (Halide::max)(r, (Halide::max)(g, b));
Expr diff = select(maxv == minv, one, maxv - minv);

Expr h = select(maxv == minv, zero,
Expand Down
16 changes: 8 additions & 8 deletions include/ion-bb-sgm/bb.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Halide::Func disparity(Halide::Func cost, int32_t disp) {
Expr e = cost(r, x, y);

Func g("argmin");
g(x, y) = Tuple(0, e.type().max());
g(x, y) = Tuple(0, (e.type().max)());
g(x, y) = tuple_select(e < g(x, y)[1], Tuple(r, e), g(x, y));

g.update().unroll(r[0]);
Expand Down Expand Up @@ -122,7 +122,7 @@ Halide::Func scanCost(Halide::Func cost, int32_t width, int32_t height, int32_t
Expr cost1 = select(rd - 1 < 0, INT32_MAX, outside_x, 0, outside_y, 0, likely(lcost(rd - 1, px, py)[0]) + PENALTY1);
Expr cost2 = select(rd + 1 >= disp, INT32_MAX, outside_x, 0, outside_y, 0, likely(lcost(rd + 1, px, py)[0]) + PENALTY1);
Expr cost3 = minCost + PENALTY2;
Expr pen = min(min(cost0, cost1), min(cost2, cost3));
Expr pen = (Halide::min)((Halide::min)(cost0, cost1), (Halide::min)(cost2, cost3));

Expr newCost = select(inside,
cast<uint16_t>(cost_wrap(rd, bx, by) + pen - minCost),
Expand Down Expand Up @@ -532,7 +532,7 @@ class SGM2 : public ion::BuildingBlock<SGM2> {
Expr cost1 = select(r.x <= 0, INT_MAX, tmp(r.x - 1, x, py)[0] + PENALTY1);
Expr cost2 = select((r.x + 1) >= mMaxDisp, INT_MAX, tmp(r.x + 1, x, py)[0] + PENALTY1);
Expr cost3 = minCost + PENALTY2;
Expr pen = min(min(cost0, cost1), min(cost2, cost3));
Expr pen = (Halide::min)((Halide::min)(cost0, cost1), (Halide::min)(cost2, cost3));
Expr newCost = cost(r.x, lx, ly) + pen - minCost;

tmp(r.x, x, r.y) = Tuple(
Expand Down Expand Up @@ -576,7 +576,7 @@ class SGM2 : public ion::BuildingBlock<SGM2> {
Expr cost1 = select(r.x <= 0, INT_MAX, lcost(r.x - 1, px, py)[0] + PENALTY1);
Expr cost2 = select((r.x + 1) >= mMaxDisp, INT_MAX, lcost(r.x + 1, px, py)[0] + PENALTY1);
Expr cost3 = minCost + PENALTY2;
Expr pen = min(min(cost0, cost1), min(cost2, cost3));
Expr pen = (Halide::min)((Halide::min)(cost0, cost1), (Halide::min)(cost2, cost3));

Expr ix = x - (mHeight - 1 - by);
Expr iy = by;
Expand Down Expand Up @@ -626,7 +626,7 @@ class SGM2 : public ion::BuildingBlock<SGM2> {
Expr cost1 = select(r.x <= 0, INT_MAX, lcost(r.x - 1, px, py)[0] + PENALTY1);
Expr cost2 = select((r.x + 1) >= mMaxDisp, INT_MAX, lcost(r.x + 1, px, py)[0] + PENALTY1);
Expr cost3 = minCost + PENALTY2;
Expr pen = min(min(cost0, cost1), min(cost2, cost3));
Expr pen = (Halide::min)((Halide::min)(cost0, cost1), (Halide::min)(cost2, cost3));

Expr ix = x - by;
Expr iy = by;
Expand Down Expand Up @@ -675,7 +675,7 @@ class SGM2 : public ion::BuildingBlock<SGM2> {
Expr cost1 = select(r.x <= 0, INT_MAX, lcost(r.x - 1, px, py)[0] + PENALTY1);
Expr cost2 = select((r.x + 1) >= mMaxDisp, INT_MAX, lcost(r.x + 1, px, py)[0] + PENALTY1);
Expr cost3 = minCost + PENALTY2;
Expr pen = min(min(cost0, cost1), min(cost2, cost3));
Expr pen = (Halide::min)((Halide::min)(cost0, cost1), (Halide::min)(cost2, cost3));

Expr newCost = select(inside,
cast<uint32_t>(
Expand Down Expand Up @@ -714,7 +714,7 @@ class SGM2 : public ion::BuildingBlock<SGM2> {
Expr cost1 = select(r.x <= 0, INT_MAX, lcost(r.x - 1, px, py)[0] + PENALTY1);
Expr cost2 = select((r.x + 1) >= mMaxDisp, INT_MAX, lcost(r.x + 1, px, py)[0] + PENALTY1);
Expr cost3 = minCost + PENALTY2;
Expr pen = min(min(cost0, cost1), min(cost2, cost3));
Expr pen = (Halide::min)((Halide::min)(cost0, cost1), (Halide::min)(cost2, cost3));

Expr newCost = select(inside,
cast<uint32_t>(
Expand Down Expand Up @@ -759,7 +759,7 @@ class SGM2 : public ion::BuildingBlock<SGM2> {
Expr cost1 = select(r.x <= 0, INT_MAX, lcost(r.x - 1, px, py)[0] + PENALTY1);
Expr cost2 = select((r.x + 1) >= mMaxDisp, INT_MAX, lcost(r.x + 1, px, py)[0] + PENALTY1);
Expr cost3 = minCost + PENALTY2;
Expr pen = min(min(cost0, cost1), min(cost2, cost3));
Expr pen = (Halide::min)((Halide::min)(cost0, cost1), (Halide::min)(cost2, cost3));

Expr newCost = select(inside,
cast<uint32_t>(
Expand Down
2 changes: 2 additions & 0 deletions test/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#ifdef HALIDE_FOR_FPGA
#include "ion-bb-fpga/bb.h"
#endif
#ifndef _WIN32
#include "ion-bb-image-io/bb.h"
#endif
#include "ion-bb-image-processing/bb.h"
#include "ion-bb-internal/bb.h"
#include "ion-bb-opencv/bb.h"
Expand Down
4 changes: 4 additions & 0 deletions test/test-rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
#include <Halide.h>
#include <HalideBuffer.h>

#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif

#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
Expand Down

0 comments on commit 6cd2d55

Please sign in to comment.