# DMIP crashes when reusing Graphs

## DMIP crashes when reusing Graphs

I ran into a DMIP problem, where code is crashing after leaving the function. This is an example of the problem.

Graph g1, g2, g3, g4, g5, g6;
Kernal k;
g1 = Src(src1);
g2 = Src(src2);

g3 = g1 * k;
g4 = g3 * 2;
g5 = g4 * 3;

g6 = g5 * g3; <-- problem

The main point is that graph g5 depends on g3, or another words, if I understand it correctly, g5 destroyed g3 so the g6 cannot be evaluated.

I fixed the problem by duplicating a lot of code:
g3 = g1 * k;
g3_copy = g1 * k;
g4 = g3 * 2;
g5 = g4 * 3;

g6 = g5 * g3_copy;

My actual code is much longer, so there is a lot of duplicated operations, which affects performance. I have a feeling there is a better solution, but I couldn't figure it out. I tried to use Copy, but again, I had to duplicate a lot of code, otherwise it kept crashing.

12 posts / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.

Hi,

I'm affraid I did not get what you are trying to do with DMIP. Would be nice if you can provide just arithmetic equation of what you want to achieve.

Is it something like this?

Image src;
Image dst;
Kernel K;
Graph f;

f = src * K

dst = ((f * 2) * 3) * f;

Regards,

Yes, that's it. Again, my actual code is much, much longer but this is a good representation. So the code was crashing until I separated the paths of the shared graph output. Maybe a better way to see this would be:

Crashing:
Image src;
Image dst;
Kernel K;
Graph f, g;

f = src * K

g = ((f * 2) * 3) * f;
dst = g * f;

Not crashing:
Image src;
Image dst;
Kernel K;
Graph f, f_copy, g;

f = src * K;
f_copy = src * K;

g = ((f * 2) * 3) * f;
dst = g * f_copy;

Again, I have many temporary Graphs variables since putting everything into one equation would be very difficult.
Thanks.

Hi,

I'm affraid I did not get what you are trying to do with DMIP. Would be nice if you can provide just arithmetic equation of what you want to achieve.

Is it something like this?

Image src;
Image dst;
Kernel K;
Graph f;

f = src * K

dst = ((f * 2) * 3) * f;

Regards,

Ok, we will take a look at this.

Regards,

Hello,

we still not able to reproduce that issue. I've attached a simple sample we made based on your description. Could you please check if this work for you?

```int main (void)
{
IppiSize  roi    = { 2048, 2048 };
IppiSize  kernel = { 7, 7 };
IppiPoint anchor = { 3, 3 };

Kernel K(idmFilterBox, kernel, anchor);

Image src(ipp8u,ippC1,roi);
Image dst(ipp8u,ippC1,roi);

Graph f;
Graph g;

f = src * K; // filtered image

g = ((f * 2) * 3) * f;

dst = g * f;

return 0;
}
```

Regards,

## Attachments:

AttachmentSize
4.57 MB

Hi, it turns out this problem is not so simple to recreate. I started with our full code, and removed everything unnecessary to see the problem. By swapping two lines of code, it will fail or pass. It turns out that the memory access violation happens at some image DPI's, but not other. Also it happens when attached to debugger, but sometimes doesn't fail when ran detached (maybe because access violation happens during tear-down). But even if the crash is hidden somehow, we always see incorrect results when we look at the produced image (last ~25 rows of the image were garbage). When I added the node copies, the crashing and garbage in the image was fixed.

Please provide an email to send you the source and related files.

Thanks, Goran

Hello,

we still not able to reproduce that issue. I've attached a simple sample we made based on your description. Could you please check if this work for you?

```int main (void)
{
IppiSize  roi    = { 2048, 2048 };
IppiSize  kernel = { 7, 7 };
IppiPoint anchor = { 3, 3 };

Kernel K(idmFilterBox, kernel, anchor);

Image src(ipp8u,ippC1,roi);
Image dst(ipp8u,ippC1,roi);

Graph f;
Graph g;

f = src * K; // filtered image

g = ((f * 2) * 3) * f;

dst = g * f;

return 0;
}
```

Regards,

Hi Goran,

I inform IPP TCE team, they will get in contact with you and create issue record in product data base where you will be able to attach necessary materials.

Regards,

I made many attempts to send the files by email, but every time I got an automated reply that the attachments have been rejected.
The code is obfuscated enough that I can attach the ZIP file here.
Thanks, Goran

## Attachments:

AttachmentSize
508.46 KB

Thank you we will take a look at this and come back to you soon.

Regards,

Quoting - Goran N
I made many attempts to send the files by email, but every time I got an automated reply that the attachments have been rejected.
The code is obfuscated enough that I can attach the ZIP file here.
Thanks, Goran

Thank you.

Igor S. Belyakov

Hello,

we have investigated your test case. It demonstrate a limitation we have in IPP 6.1 DMIP. The DMIP slice size in IPP 6.1 can't be less than half of filter kernel height. So for your particular case we would recommend to set manually slice size like this:

```        // In 6.1 for correct processing without crash slice size must be more than half of kernel size.
status = GR.Compile(5);
if ( status != idmOK )
{
return false;
}
status = GR.Execute();
if ( status != idmOK )
{
return false;
}
```

This limitation will be removed in the next version of DMIP. Thanks for helping us to discover this.
Regards,

Quoting - Goran N
I ran into a DMIP problem, where code is crashing after leaving the function. This is an example of the problem.

Graph g1, g2, g3, g4, g5, g6;
Kernal k;
g1 = Src(src1);
g2 = Src(src2);

g3 = g1 * k;
g4 = g3 * 2;
g5 = g4 * 3;

g6 = g5 * g3; <-- problem

The main point is that graph g5 depends on g3, or another words, if I understand it correctly, g5 destroyed g3 so the g6 cannot be evaluated.

I fixed the problem by duplicating a lot of code:
g3 = g1 * k;
g3_copy = g1 * k;
g4 = g3 * 2;
g5 = g4 * 3;

g6 = g5 * g3_copy;

My actual code is much longer, so there is a lot of duplicated operations, which affects performance. I have a feeling there is a better solution, but I couldn't figure it out. I tried to use Copy, but again, I had to duplicate a lot of code, otherwise it kept crashing.

Hi,
I like to inform you that, we have fixed this issue in the latest release of IPP. Please refer to below forum link to get more information like package download, installation and list of bug fixed in this relase.