IntelLabs / ParallelAccelerator.jl

The ParallelAccelerator package, part of the High Performance Scripting project at Intel Labs
BSD 2-Clause "Simplified" License
294 stars 32 forks source link

OptFramework failed to optimize function when using function wrapper #156

Open NaelsonDouglas opened 6 years ago

NaelsonDouglas commented 6 years ago

Hello.

I'm trying to execute the below, but I'm getting the following message julia> include("simple_ips.jl") OptFramework failed to optimize function ##process#658 in optimization pass ParallelAccelerator.Driver.toDomainIR with error AssertionError("")

It's basically a wrapper on the gaussian-blur example.

What am I doing wrong since ParallelAccelerator is not able to optimize the function?

using Images
using ImageView
using ImageMagick
using TestImages
using FileIO
using ParallelAccelerator
using DocOpt
using Images

end

function blur(img, iterations)
    buf = copy(img)
    runStencil(buf, img, iterations, :oob_src_zero) do b, a
       b[0,0] =
      (a[-2,-2] * 0.003  + a[-1,-2] * 0.0133 + a[0,-2] * 0.0219 + a[1,-2] * 0.0133 + a[2,-2] * 0.0030 +
       a[-2,-1] * 0.0133 + a[-1,-1] * 0.0596 + a[0,-1] * 0.0983 + a[1,-1] * 0.0596 + a[2,-1] * 0.0133 +
       a[-2, 0] * 0.0219 + a[-1, 0] * 0.0983 + a[0, 0] * 0.1621 + a[1, 0] * 0.0983 + a[2, 0] * 0.0219 +
       a[-2, 1] * 0.0133 + a[-1, 1] * 0.0596 + a[0, 1] * 0.0983 + a[1, 1] * 0.0596 + a[2, 1] * 0.0133 +
       a[-2, 2] * 0.003  + a[-1, 2] * 0.0133 + a[0, 2] * 0.0219 + a[1, 2] * 0.0133 + a[2, 2] * 0.0030)
    return a, b
    end
    return img
end

##session_id doesnt do anything in the code yet
@acc function process(session_id,kernel,input, iterations)
    img = load(input)
    img2 = kernel(img,iterations)
    save("portinari-blur.png",img2)

process(1,blur,"portinari.png")
DrTodd13 commented 6 years ago

One thing I notice directly is that you have @acc on process instead of blur. Is there a reason you did that?

lagefreitas commented 6 years ago

hi @DrTodd13, cc @NaelsonDouglas

Thanks for the quick answer. We applied ParallelAccelerator to a generic function called process because our prototype doesn't know which function will be called by the user. It could be any function that ParallelAccelerator is able to accelerate, e.g., blur.

Would there be a better (or more appropriate) way of doing this?

NaelsonDouglas commented 6 years ago

Hello @DrTodd13, thanks for the answer. It's because blur is working as a test function. In our project we are going to use generic functions/kernels.

That's the deal: 1: We create the process function (which is not fully implemented in this code snippet I posted) 2: This function gets another function (a kernel) and a path to an image 3: Then we apply this kernel to the image with

Since blur is very intuitive and it was avaliable in the example repository, we are using it for tests, but in the future we will be able to use any kernel we want.

But...is it wrong to use @acc in the process function?

DrTodd13 commented 6 years ago

In general, you apply @acc to functions where you expect a lot of computation to take place directly in. So, if you had 10 kernels, you'd put @acc on all of them (or declare an @acc block and put them in the block). You don't expect a lot of computation in process itself, just a few function calls, so that should most likely not be @acc.

NaelsonDouglas commented 6 years ago

That makes a lot of sense. Thanks for the information.

I just put the @acc in the blur function instead of process, but the OptFramework failed to optimize function keeps showing up. 😢

Is there any lead for me to find what's going on?

Anyways, the blur filter is working properly, there's the before and after generated by the code I sent: portinari

DrTodd13 commented 6 years ago

Can you post a minimal example of the new error?

NaelsonDouglas commented 6 years ago

Here's the error: https://asciinema.org/a/59YWI6IzZnIA4UJvf6JOhnZM9 It's actually the same error.

And here is the code:

using Images
using ImageView
using ImageMagick
using TestImages
using FileIO
using ParallelAccelerator

using DocOpt
using Images

@acc function blur(img, iterations)
    buf = copy(img)
    runStencil(buf, img, iterations, :oob_src_zero) do b, a
       b[0,0] =
      (a[-2,-2] * 0.003  + a[-1,-2] * 0.0133 + a[0,-2] * 0.0219 + a[1,-2] * 0.0133 + a[2,-2] * 0.0030 +
       a[-2,-1] * 0.0133 + a[-1,-1] * 0.0596 + a[0,-1] * 0.0983 + a[1,-1] * 0.0596 + a[2,-1] * 0.0133 +
       a[-2, 0] * 0.0219 + a[-1, 0] * 0.0983 + a[0, 0] * 0.1621 + a[1, 0] * 0.0983 + a[2, 0] * 0.0219 +
       a[-2, 1] * 0.0133 + a[-1, 1] * 0.0596 + a[0, 1] * 0.0983 + a[1, 1] * 0.0596 + a[2, 1] * 0.0133 +
       a[-2, 2] * 0.003  + a[-1, 2] * 0.0133 + a[0, 2] * 0.0219 + a[1, 2] * 0.0133 + a[2, 2] * 0.0030)
    return a, b
    end
    return img
end

function process(session_id,kernel,input, iterations)
    img = load(input)
    img2 = kernel(img,iterations)
    save("portinari-blur.png",img2)
end

process(1,blur,"portinari.png",1)
DrTodd13 commented 6 years ago

I wasn't seeing the same problem you were but it may have just been manifesting differently. I think I may have fixed it. You can try to checkout the master branch of ParallelAccelerator and let me know if it works. Thanks for your patience!

NaelsonDouglas commented 6 years ago

Hello. I updated ParallelAccelerator, but the error persists to me. image

Can you show-me the environment you are using with Pkg.installed() in order to me use exactly the same versions you are using to make it work?