Re: [eigen] Cost of a map operation |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Cost of a map operation
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Tue, 20 Oct 2009 11:20:56 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=fsQT4/+lrgqt6t1y6RgORXC5/mW/7M/GJ422v2Cn9qM=; b=Y6sic6J5PPx3Wk+Ex2+kY/CZwXLsYh+OPmIqTeLedB2ry16n8zWm6rPSMRL2AwXB/U tyTsMMVZQcyhxlSWRkyyc8zDdLHczplJgmVH/md2m1Qf2e+SRElGxJTjbA/mK6El5YDx ygmF73SwMTNehZAw0dhnB7/f2R1dxkmnjSW1s=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=sY/BGczQ/t7Gx4jkYtbDvmSin3rdOvP3o5Y3rfW2JgslU1hOJzNjKYHR5IWXLWRW5s xJYdCziDlIOTwdzR2I1SUBfJhcwhxSB5Icn33YKTCXvSYClJA5jsgjS1hv0UeIRX+L3G 02jPV9Z03U+O5Iz9ZbmW0HqP6ZX6K9Fy9eXpw=
2009/10/20 Rohit Garg <rpg.314@xxxxxxxxx>:
> On Wed, Sep 2, 2009 at 6:02 PM, Gael Guennebaud
> <gael.guennebaud@xxxxxxxxx> wrote:
>> perhaps here you don't want to copy it to an Eigen vector but directly
>> use *address as an Eigen vector. For that you simply declare:
>>
>> Map<AddressVector_t,ForceAligned> AddressVector(address);
>
> Sorry to revive an old thread for this but the above trick doesn't
> work for mapping dynamic matrices. I tried this
>
> ============
> Map<MatrixXi, ForceAligned>
> dataMatrix(dataPtr,packetPtr->fileHeader.rows,packetPtr->fileHeader.columns);
> ============
> and it refused to compile.
strange. can you show the compiler errors?
> But this is working
>
> ============
> dataMatrix = Map<MatrixXi,ForceAligned>(dataPtr,packetPtr->fileHeader.rows,packetPtr->fileHeader.columns);
> ============
>
> I just want to know how to use map here to avoid a memcpy
>>
>> and use AddressVector as any other Eigen vector, e.g.:
>>
>> AddressVector *= 2;
>>
>> that is the same as directly modifying address:
>>
>> for(int i=0; bla; bla)
>> address[i] *= 2;
>>
>> with all Eigen's goodies.
>>
>> cheers,
>> gael.
>>
>> On Wed, Sep 2, 2009 at 2:16 PM, Benoit Jacob<jacob.benoit.1@xxxxxxxxx> wrote:
>>> This is as efficient as it could be: typically, this expands to
>>> nothing more than:
>>>
>>> for(int i = 0; i < cordNum; ++i)
>>> AddressVector[i] = address[i];
>>>
>>> and then 1) Eigen unrolls this if appropriate and 2) Eigen vectorizes
>>> this if possible.
>>>
>>> Basically, the Map object itself is just an expression, so its
>>> construction is cheap at least, and in practice the compiler is able
>>> to avoid actually creating it, everything gets "inlined".
>>>
>>> Tip: you could check the resulting assembly code for yourself, just
>>> put asm comments around this, asm("#hello"); , and use gcc -S to get
>>> the assembly...
>>>
>>> Benoit
>>>
>>>
>>>
>>> 2009/9/2 Rohit Garg <rpg.314@xxxxxxxxx>:
>>>> What is the cost of this map operation?
>>>>
>>>> AddressVector_t AddressVector = Map<AddressVector_t,ForceAligned>(address)
>>>>
>>>> where AddressVector_t itself is a typedef for
>>>>
>>>> typedef Matrix<int,cordNum,1> AddressVector_t;
>>>>
>>>> cordNum is a compile time constant.
>>>>
>>>> This map operation occurs in inner loop of my application, so I want
>>>> to know, how costly is it gonna be? I mean with what use in mind was
>>>> it written for?
>>>> --
>>>> Rohit Garg
>>>>
>>>> http://rpg-314.blogspot.com/
>>>>
>>>> Senior Undergraduate
>>>> Department of Physics
>>>> Indian Institute of Technology
>>>> Bombay
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>>
>
>
>
> --
> Rohit Garg
>
> http://rpg-314.blogspot.com/
>
> Senior Undergraduate
> Department of Physics
> Indian Institute of Technology
> Bombay
>
>
>