[Insight-developers] Explicit instantiation

Gaetan Lehmann gaetan.lehmann at jouy.inra.fr
Tue Apr 25 07:16:30 EDT 2006


On Fri, 21 Apr 2006 16:15:18 +0200, Brad King <brad.king at kitware.com>  
wrote:

> Gaetan Lehmann wrote:
>> I'm not sure to understand what the explicit instantiation does.
>> It build some template specialization for a restricted set of template   
>> arguments, and put this code in the ITKCommon lib ?
>
> This is correct.
>
>> What is the benefit ? Compilation time ? executable size ?
>
> Both.  Right now the ITK build tree is over 7GB with all the tests and  
> Tcl/Python wrapping on Linux.  Alot of the space comes because every  
> object file that gets built has its own copy of implicitly instantiated  
> templates like "itk::Image<unsigned char, 2>".  Most of these duplicate  
> symbols are merged by the linker, which means that the compiler wasted  
> time compiling them in the first place.  Even after the linker merges  
> them each executable still has its own copy, even with shared libraries  
> enabled.
>
> The explicit instantiation support puts the common instantiations in one  
> library ahead of time and then instructs the compiler not to build those  
> instantiations elsewhere.  This should significantly reduce the disk  
> space and compile time needed to build ITK with tests and wrapping.
>
> If you look at the Code/Common/Templates directory you will see  
> something that looks a bit like the wrapper configuration files.  In the  
> future I plan to find a way to merge these so that all explicit  
> instantiations are wrapped.  Building wrappers for them should be much  
> faster because the .txx files do not need to be included at all since  
> now only calls to the code need be compiled in the wrappers instead of  
> the code itself in the form of implicit instantiations.
>

Would it be possible to use explicit template instantiation to produce  
some libs shared between all the languages wrapped ? WrapITK is already  
provide a convenient way to select a consistent set of template  
parameters, and is also able to generate code - perhaps can we use it to  
generate code for explicit instantiation ?
- Select instantiations with WrapITK
- build the selected instantiation in (several) libs
- build the wrappers for all the selected languages
- link the wrappers with the libs produce before
It would highly decrease the build time with several languages, and highly  
decrease the total size of binary files.
It seem that the libraries stay in memory when the program exit, and so,  
reloading the module in python would be a lot faster.

Gaetan

-- 
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
http://voxel.jouy.inra.fr


More information about the Insight-developers mailing list