[GRASS-dev] [GRASS GIS] #3293: r.texture: very slow when size is increased

#3293: r.texture: very slow when size is increased
-----------------------------+-------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.4.0
Component: Raster | Version: svn-trunk
Keywords: r.texture speed | CPU: Unspecified
Platform: Unspecified |
-----------------------------+-------------------------
Running

{{{
r.texture -a ortho_2001_t792_1m size=27 out=text_ortho_27
}}}

in the NC demo data set took the following time:

{{{
real 339m54.922s
user 339m44.824s
sys 0m5.464s
}}}

This seems excessively long, especially when the relevant literature cites
common sizes of 20-50 (see #3210 for a discussion).

It would be great if this could somehow be accelerated.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3293&gt;
GRASS GIS <https://grass.osgeo.org>

#3293: r.texture: very slow when size is increased
--------------------------+-----------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.4.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture speed
       CPU: Unspecified | Platform: Unspecified
--------------------------+-----------------------------

Comment (by mmetz):

Replying to [ticket:3293 mlennert]:
> Running
>
>
> {{{
> r.texture -a ortho_2001_t792_1m size=27 out=text_ortho_27
> }}}
>
> in the NC demo data set took the following time:
>
>
> {{{
> real 339m54.922s
> user 339m44.824s
> sys 0m5.464s
> }}}
>
> This seems excessively long, especially when the relevant literature
cites common sizes of 20-50 (see #3210 for a discussion).

Note that e.g. Haralick et al. (1973) did not use a moving window
approach, instead texture measurements were calculated for selected blocks
and the output is not a raster map but a single value for each texture
measurement and each block.
>
> It would be great if this could somehow be accelerated.

Maybe by processing moving windows in parallel, at the cost of allocating
/ freeing memory for each moving window.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3293#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#3293: r.texture: very slow when size is increased
--------------------------+-----------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.4.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture speed
       CPU: Unspecified | Platform: Unspecified
--------------------------+-----------------------------

Comment (by mlennert):

Replying to [comment:1 mmetz]:
> Replying to [ticket:3293 mlennert]:
> > Running
> >
> >
> > {{{
> > r.texture -a ortho_2001_t792_1m size=27 out=text_ortho_27
> > }}}
> >
> > in the NC demo data set took the following time:
> >
> >
> > {{{
> > real 339m54.922s
> > user 339m44.824s
> > sys 0m5.464s
> > }}}
> >
> > This seems excessively long, especially when the relevant literature
cites common sizes of 20-50 (see #3210 for a discussion).
>
> Note that e.g. Haralick et al. (1973) did not use a moving window
approach, instead texture measurements were calculated for selected blocks
and the output is not a raster map but a single value for each texture
measurement and each block.

Yes. But I find the pixel-by-pixel version quite nice ! :wink: This said, a
per-object texture measurement would also be nice... See #2111.

> >
> > It would be great if this could somehow be accelerated.
>
> Maybe by processing moving windows in parallel, at the cost of
allocating / freeing memory for each moving window.

Yes, I've thought about this as well. This seems like a perfect example of
a module that could profit from parallelisation across as many
cores/threads the user choses. Memory usage is very low, so this will not
be a bottleneck (except for large images as the module still reads in the
entire data, no ?). And allocation only has to happen once at the
beginning, and then you can just use the allocated window throughout, or ?

Might be interesting to benchmark where exactly most time is lost. Any
hints on how to do that ?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3293#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#3293: r.texture: very slow when size is increased
--------------------------+-----------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.4.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture speed
       CPU: Unspecified | Platform: Unspecified
--------------------------+-----------------------------

Comment (by mmetz):

Replying to [comment:2 mlennert]:
> Replying to [comment:1 mmetz]:
> > Replying to [ticket:3293 mlennert]:
[...]
> > >
> > > It would be great if this could somehow be accelerated.
> >
> > Maybe by processing moving windows in parallel, at the cost of
allocating / freeing memory for each moving window.
>
> Yes, I've thought about this as well. This seems like a perfect example
of a module that could profit from parallelisation across as many
cores/threads the user choses. Memory usage is very low, so this will not
be a bottleneck (except for large images as the module still reads in the
entire data, no ?). And allocation only has to happen once at the
beginning, and then you can just use the allocated window throughout, or ?

No, because if you process moving windows in parallel, you process several
moving windows at the same time. Therefore you would need to allocate +
free memory for each moving window, otherwise the different moving windows
would overwrite each other's results.
>
> Might be interesting to benchmark where exactly most time is lost. Any
hints on how to do that ?

You could use profiling tools, e.g. pprof.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3293#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>

#3293: r.texture: very slow when size is increased
--------------------------+-----------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.4.0
Component: Raster | Version: svn-trunk
Resolution: | Keywords: r.texture speed
       CPU: Unspecified | Platform: Unspecified
--------------------------+-----------------------------

Comment (by mlennert):

Replying to [comment:3 mmetz]:
> Replying to [comment:2 mlennert]:
> > Replying to [comment:1 mmetz]:
> > > Replying to [ticket:3293 mlennert]:
> [...]
> > > >
> > > > It would be great if this could somehow be accelerated.
> > >
> > > Maybe by processing moving windows in parallel, at the cost of
allocating / freeing memory for each moving window.
> >
> > Yes, I've thought about this as well. This seems like a perfect
example of a module that could profit from parallelisation across as many
cores/threads the user choses. Memory usage is very low, so this will not
be a bottleneck (except for large images as the module still reads in the
entire data, no ?). And allocation only has to happen once at the
beginning, and then you can just use the allocated window throughout, or ?
>
> No, because if you process moving windows in parallel, you process
several moving windows at the same time. Therefore you would need to
allocate + free memory for each moving window, otherwise the different
moving windows would overwrite each other's results.

Yes, but you would only need one window per process, and you would only
allocate each process window once, at the beginning, or ?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3293#comment:4&gt;
GRASS GIS <https://grass.osgeo.org>