Coder Social home page Coder Social logo

Calculation range fail about halide-hls HOT 10 CLOSED

jingpu avatar jingpu commented on June 19, 2024
Calculation range fail

from halide-hls.

Comments (10)

xuanyoya avatar xuanyoya commented on June 19, 2024 1

In you original code, both input and output are 3 dimensional, especially you bound the 3rd dimension of output using output.bound(c, 0, 3); so please use 3 dimensions in run.cpp. If you want to reduce the 3rd dimension of input, please change

local_sum(x, y, c) += cast<uint16_t>(in(x+r.x, y+r.y, c)) * weight(r.x+2, r.y+2); to
local_sum(x, y) += cast<uint16_t>(in(x+r.x, y+r.y, r.z)) * weight(r.x+2, r.y+2);

And also change some other code accordingly. But in that case, it is not in the scope of this issue, so the current issue will be closed.

from halide-hls.

xuanyoya avatar xuanyoya commented on June 19, 2024

There are several issues in your code. Main reason is your tile size is 1 x 1, and window size is 3 x 3, that makes the maximum size of your image tile -1 x -1. What you should change in your code is:

  1. local_sum(x, y, c) += cast<uint16_t>(in(x+r.x, y+r.y, c)) * weight(r.x+2, r.y+2); change to local_sum(x, y, c) += cast<uint16_t>(in(x+r.x, y+r.y, c)) * weight(r.x+1, r.y+1); so that the weight is accessed at the right position.
  2. hw_output.tile(x, y, xo, yo, xi, yi, 1, 1); change to hw_output.tile(x, y, xo, yo, xi, yi, 16, 16);, note 16 is just an example, but you should use a number that larger than the window size.
  3. input_buf(x,y,c) = clamped(x,y,c); get removed, since it is not used.

from halide-hls.

chingyi071 avatar chingyi071 commented on June 19, 2024

Thank you @xuanyoya for detail description. However, the max(-1) problem still occur after the modifications. Moreover, I have tried to use different size of input buffer, but it didn't change anything. Is there any other potential problem?

from halide-hls.

xuanyoya avatar xuanyoya commented on June 19, 2024

@chingyi071 I didn't read your run.cpp file before. But this time, I realized you also have another error in this file. Since you are doing a convolution with window 3 x 3, so the output image size will be smaller than the input image size, you should NOT specify your output image to be:

    BufferMinimal<uint8_t> out_native(input.width(),input.height());
    BufferMinimal<uint8_t> out_hls(input.width(), input.height());

Instead, change input.width() and input.height() to some numbers that smaller than or equal to input.width() - 2 and input.height() - 2 .

Let me know the result. If that passes, I will close this issue.

from halide-hls.

chingyi071 avatar chingyi071 commented on June 19, 2024

@xuanyoya I modify it but it still fail. But the error message become Error: Output buffer output is accessed at 2, which is beyond the max (-1) in dimension 2. The original error message is accessed at 0. I'm not sure whether this phenomenon can help you

from halide-hls.

xuanyoya avatar xuanyoya commented on June 19, 2024

@chingyi071 Besides, for this kind of errors, you can just try the same program and same schedule with original C backend or with original Halide repo. If you see this error occurs with the original C backend or original Halide repo, then the fastest way for you debug is to post this question on stackoverflow or Halide developer mailing list.

from halide-hls.

xuanyoya avatar xuanyoya commented on June 19, 2024

Since you are doing repeat_edge as clamped = BoundaryConditions::repeat_edge(input);, I don't think my previous suggestion is helpful. The change you should make is

    BufferMinimal<uint8_t> out_native(input.width(),input.height(), input.channels());
    BufferMinimal<uint8_t> out_hls(input.width(), input.height(), input.channels());

Besides, for this line pipeline_hls(input, weight, out_native);, it should be pipeline_hls(input, weight, out_hls);

from halide-hls.

chingyi071 avatar chingyi071 commented on June 19, 2024

The dimension of input image will be reduced from 3 to 2 in the function, so I remove input.channels() in output buffer declaration. I fix the input argument in pipeline_hls() but it still failed.

from halide-hls.

xuanyoya avatar xuanyoya commented on June 19, 2024

I didn't see how you reduced the dimension from 3 to 2, and I have tried with my modification, it already passed.

from halide-hls.

chingyi071 avatar chingyi071 commented on June 19, 2024

@xuanyoya Sorry I just use reduced version of my function. This code does not reduce the dimension. And I pass the test. Thank you very much

from halide-hls.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.