Reply
 
Thread Tools Display Modes   
 
logarithm function trick
 
Old 25/12/2008, 12:50 Reply With Quote   #1
pe-e-be
Alien dari lab GAIB
 
pe-e-be's Avatar
 
Join Date: Jul 2005
Location: lab gaib itb, bandung
Posts: 1,587
pe-e-be is on a distinguished road
Send a message via Yahoo to pe-e-be pe-e-be is offline
logarithm function trick

Ada algoritma yang pake fungsi logaritma untuk setiap titik ketika rendering, mengingat fungsi logaritma lambatnya minta ampun.
Quote:
salah satu algoritma yang gw temukan untuk menghitung logaritma melibatkan pembagian iteratif dalam 2 tahap dan pembagian adalah AFAIK operasi aritmetika sederhana yang perlu cpu cycle paling mahal (dibanding perkalian)
kira-kira dari solusi di bawah (tambahin klo belum ada) lebih baik pilih yang mana dan kenapa? thx b4

- SLUT (simply look up table)?
- Algoritma numerik yang lebih cepat (pake binary log atau fixed point number)?
- program di gpu?
__________________
liku-liku hidup.
game, dapur dan perspektif.
hire me here
   
 
 
Old 25/12/2008, 13:37 Reply With Quote   #2
L_O_J
Ulat tak berbulu
 
L_O_J's Avatar
 
Join Date: Dec 2003
Posts: 1,674
L_O_J is on a distinguished road
Send a message via Yahoo to L_O_J L_O_J is offline
dari yang paling mudah menurut gue sih:

- LUT
- GPU
- Algo baru


Masalah yang paling baik, menurut gue trade off. LUT IMO yang paling gak tepat tapi paling cepet.
__________________
"Experience is something that you got when you don't get something that you want" - Randy Pausch ( The Last Lecture )
"The brick wall is there for a reason, to separate those who really want it and the rest" - Randy Pausch ( The Last Lecture )
   
 
 
Old 25/12/2008, 15:46 Reply With Quote   #3
pe-e-be
Alien dari lab GAIB
 
pe-e-be's Avatar
 
Join Date: Jul 2005
Location: lab gaib itb, bandung
Posts: 1,587
pe-e-be is on a distinguished road
Send a message via Yahoo to pe-e-be pe-e-be is offline
klo mo pake LUT mesti tau batasan memori jg kayaknya. klo mo per-bit bisa sampe 4GB (IEEE 754) buat LUT.

barusan dapet algoritma berbasis LUT yang cuma pake 64K memori dan presisi sampe 1e-7. setelah gw benchmark (di CPU), lumayan 4 kali lebih cepat.



klo yang GPU gimana lil?
__________________
liku-liku hidup.
game, dapur dan perspektif.
hire me here

Last edited by pe-e-be : 25/12/2008 at 15:49.
   
 
 
Old 25/12/2008, 23:50 Reply With Quote   #4
Kiki
Kiki++
 
Kiki's Avatar
 
Join Date: Sep 2005
Posts: 801
Kiki is on a distinguished road
Kiki is offline
hehehe ... mo nimbrung ... bikin fungsi logaritma pake SSE, masalahnya :

1. nggak gitu akurat, maklum cuma evaluasi maclaurin series cuma 4 suku saja
2. Only work for x where 0 < x < 2 (open interval)
3. No guarantee it is faster

ini kodenya :
Code:
#include <cstdio> #include <cmath> #include <xmmintrin.h> float maclaurin(float val){ __declspec(align(16) ) float tmp[4] = { 1.0F,1.0F,1.0F,0.0F}; __declspec(align(16) ) float multiplier[4] = { 1.0F,-0.5F,0.33333333F,-0.25F}; tmp[3] = val; __m128 vec1 = _mm_load_ps(tmp); __m128 vec2 = _mm_shuffle_ps( vec1,vec1,0xF4); __m128 vec3 = _mm_shuffle_ps( vec1,vec1,0xFC); __m128 vec4 = _mm_shuffle_ps( vec1,vec1,0xFF); __m128 acc = _mm_mul_ps(vec1, vec2); acc = _mm_mul_ps(acc, vec3); vec1 = _mm_load_ps(multiplier); acc = _mm_mul_ps(acc, vec4); acc = _mm_mul_ps(acc,vec1); vec1 = _mm_shuffle_ps(acc,acc, 0xE4); vec2 = _mm_shuffle_ps(acc,acc, 0x39); vec3 = _mm_shuffle_ps(acc,acc, 0x4E); vec4 = _mm_shuffle_ps(acc,acc, 0x93); acc = _mm_add_ps(vec1,vec2); acc = _mm_add_ps( acc, vec3); acc = _mm_add_ps(acc, vec4); float res; _mm_store_ss(&res,acc); return res; } float my_log(float x){ return maclaurin(x - 1); } int main(){ float reference = logf(1.3F); float target = my_log(1.3F); printf(" reference = %g , target = %g\n", reference, target); }
di komputer gw, outputnya :

reference = 0.262364 , target = 0.261975

not bad ...
__________________
Wir haben die Kunst, damit wir nicht an der Wahrheit zugrunde gehen.

Last edited by Kiki : 25/12/2008 at 23:56.
   
 
 
Old 26/12/2008, 00:19 Reply With Quote   #5
L_O_J
Ulat tak berbulu
 
L_O_J's Avatar
 
Join Date: Dec 2003
Posts: 1,674
L_O_J is on a distinguished road
Send a message via Yahoo to L_O_J L_O_J is offline
Wogh maap om peb, otak gue cuman nyampe ke LUT, yang GPU sama Algo baru mah gue asumsi dari tingkat kesulitannya, maksudnya creating a new faster algo itu jelas lebih sulit daripada utilize GPU toh . kalo coding GPU om kiki noh .
__________________
"Experience is something that you got when you don't get something that you want" - Randy Pausch ( The Last Lecture )
"The brick wall is there for a reason, to separate those who really want it and the rest" - Randy Pausch ( The Last Lecture )
   
 
 
Old 26/12/2008, 09:24 Reply With Quote   #6
Kiki
Kiki++
 
Kiki's Avatar
 
Join Date: Sep 2005
Posts: 801
Kiki is on a distinguished road
Kiki is offline
Quote:
Originally Posted by L_O_J View Post
kalo coding GPU om kiki noh .
kok gw ? biar GPU itu mesin SIMD, kl tiap elemennya cuma integer 8 bit, gw bisa apa ? (nggak pernah make floating point format)
__________________
Wir haben die Kunst, damit wir nicht an der Wahrheit zugrunde gehen.
   
   Reply   


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT +7. The time now is 19:49.


skin developed by: uray
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.