tag:blogger.com,1999:blog-11210141448592306852008-05-03T02:43:57.757-07:00FreeMat BlogDemetrioshttp://www.blogger.com/profile/06305976623803819238noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-1121014144859230685.post-46189278825587092282008-04-14T14:25:00.000-07:002008-04-14T15:09:09.211-07:00RantSometimes, Matlab language drives me nuts. It appears that software engineers just went for the most illogical and incorrect design decisions. Here's an example:<br /><br />int16(100000000) returns 32767 (So, in Matlab integers are not a group. Why not go for modular arithmetic?)<br /><br />int16(1)+0.4 returns an answer of class int16 (So, Matlab demotes(!) types in arithmetic expressions.)<br /><br />(int16(1)+0.4)+0.4 returns 1, but<br />int16(1)+(0.4+0.4) returns 2 (So, in Matlab addition is not associative!)<br /><br /><br />Why? Oh, Why?Eugenehttp://www.blogger.com/profile/11701476239862715231noreply@blogger.comtag:blogger.com,1999:blog-1121014144859230685.post-1575296645667445772008-04-03T20:50:00.000-07:002008-04-03T20:59:20.178-07:00What we are working on...I thought I would post an update:<br /><br />Samit is finishing up new array class. The new arrays will simplify writing matlab functions and improve performance.<br /><br />I've been trying to fix a very annoying bug - zooming on a image has unpredictable results. In the process I'm cleaning up some handle graphics code. I think I'm going to cleanup more code in libgraphics.Eugenehttp://www.blogger.com/profile/11701476239862715231noreply@blogger.comtag:blogger.com,1999:blog-1121014144859230685.post-78877939602260295052008-02-29T14:03:00.000-08:002008-04-03T21:01:48.014-07:00Why JIT? How to JIT?I started using Matlab circa version 4 and I still cringe every time I have to write a loop in Matlab. The main reason is that I got conditioned (like the generations of matlab users) that loops are really slow because they have to be interpreted. Matrix or index operations on the other hand turn into internal function calls and are fast. The old view - almost always using clever indexing one can avoid loops. However, this is 21st century and we have better ways...<br /><br />The goal for using JIT (just-in-time compilation) is to speed up interpreted code by compiling it in run time. This is very tricky for dynamic languages such as Matlab (also Python, Perl, etc. ). The main reason is that the variable types are determined at runtime. For example:<br /><pre><br />for j=1:10<br /> if j > 5<br /> a = int8(j);<br /> else<br /> a = float(j);<br /> end<br />end<br /></pre><br />What's the type of a? Compiler has to know the variable size and type to emit correct code. One can imagine using an object to represent variables (the object would carry a type and pointer to memory where data is stored) and assignement operator which would assign both value and type. However, such implementation results in code that is not much faster than interpreted code.<br /><br />However, code like the snippet above is rare. In most cases variables have well defined type at runtime. For such a code we can generate very fast machine code.<br /><br />Here's the current approach that FreeMat takes is:<br /><ul><li>Compile code that would most benefit from speedup (loops, functions)</li><li>If code cannot be compiled fall back to using the interpreter (slow, but at least you always get an answer).</li><li>Check for variable type changes between running JIT compiled code.</li><li>JIT compiled code works on the same data structures as the interpreter.</li></ul>Samit and I looked at three jit compilers: Java JIT, Mono JIT, and <a href="http://www.llvm.org/">LLVM</a>. Java JIT seemed better suited for Java language. Mono JIT isn't mature.<br /><br />LLVM was our choice. It is not perfect - the library is really huge and quite hard to compile and use. However, you can generate and optimize code on the fly and get near optimal performance (the only thing you can't do with JIT code is interprocedural optimizations).<br /><br />We plan to have functional JIT compiler in Freemat 4.Eugenehttp://www.blogger.com/profile/11701476239862715231noreply@blogger.comtag:blogger.com,1999:blog-1121014144859230685.post-48128509742424052112008-02-26T22:49:00.000-08:002008-02-26T23:09:49.972-08:00What's coming in version 4.<span style="font-size:100%;">I just wanted to update on the current Freemat developments. We are planning some major changes for version 4:<br /><br /></span><ul><li>Just-In-Time compiler.<br /></li><li>Type system compatible with Matlab.</li><li>New build system using cmake (native build using Visual Studio Express under Windows).</li><li>Dynamic linking with BLAS libraries.</li></ul>The development is happening in two branches FreeMat4 and array_rework. Check it out!Eugenehttp://www.blogger.com/profile/11701476239862715231noreply@blogger.comtag:blogger.com,1999:blog-1121014144859230685.post-26101365758024901102008-02-25T14:19:00.000-08:002008-02-26T23:10:32.615-08:00Freemat 3.6 on the horizonFreemat team is working on the 3.6 release. This is planned as a bugfix release. Well, a few compatibility changes will thrown in too.<br /><br />The release is planned for early March. Stay tuned....Eugenehttp://www.blogger.com/profile/11701476239862715231noreply@blogger.com