Just-in-time compiler

(Difference between revisions)
Jump to: navigation, search
m (See Also)
m
Line 1: Line 1:
[[HornetsEye]] makes use of [http://dotgnu.org/libjit-doc/libjit.html libjit]. This means that you can even define and compile
+
The Ruby-extension [[HornetsEye]] makes use of [http://dotgnu.org/libjit-doc/libjit.html libjit]. This means that you can even
methods during runtime. Here is a 46 MByte video demonstrating this capability. I recommend to watch the
+
define and compile methods during runtime. Here is a 46 MByte video demonstrating this capability. I recommend to watch the
 
[http://vision.eng.shu.ac.uk/jan/jitdemo.ogg OGG video] instead of the Shockwave video. It is of much higher quality.
 
[http://vision.eng.shu.ac.uk/jan/jitdemo.ogg OGG video] instead of the Shockwave video. It is of much higher quality.
  
Line 13: Line 13:
 
         pluginspage="http://www.macromedia.com/go/getflashplayer"/>
 
         pluginspage="http://www.macromedia.com/go/getflashplayer"/>
 
       <div class="thumbcaption" >
 
       <div class="thumbcaption" >
         Demonstration of using the just-in-time compiler with HornetsEye. You can also view the <a href="http://vision.eng.shu.ac.uk/jan/jitdemo.ogg">OGG-video of the JIT demo</a> which is of higher quality. The video was created using <a href="http://recordmydesktop.sourceforge.net/">recordMyDesktop</a>. The <a href="http://en.wikipedia.org/wiki/Image:Hong_Kong_Night_Skyline.jpg">Hong Kong skyline</a> was used as a background picture
+
         Demonstration of an interactive Ruby-session using libjit and HornetsEye. You can also view the <a href="http://vision.eng.shu.ac.uk/jan/jitdemo.ogg">OGG-video of the JIT demo</a> which is of higher quality. The video was created using <a href="http://recordmydesktop.sourceforge.net/">recordMyDesktop</a>. The <a href="http://en.wikipedia.org/wiki/Image:Hong_Kong_Night_Skyline.jpg">Hong Kong skyline</a> was used as a background picture
 
       </div>
 
       </div>
 
     </div>
 
     </div>

Revision as of 16:52, 24 November 2008

The Ruby-extension HornetsEye makes use of libjit. This means that you can even define and compile methods during runtime. Here is a 46 MByte video demonstrating this capability. I recommend to watch the OGG video instead of the Shockwave video. It is of much higher quality.

Demonstration of an interactive Ruby-session using libjit and HornetsEye. You can also view the OGG-video of the JIT demo which is of higher quality. The video was created using recordMyDesktop. The Hong Kong skyline was used as a background picture
# Load colour image.
img = MultiArray.load_rgb24( "/home/engjw/Documents/pictures/miraculix.jpg" )
# Display the image.
img.show
# Convert the image to grey-level floating point.
gimg = img.to_sfloat
# Display grey-level image.
gimg.show
# Downsample the image with a sampling-rate of 2 in each direction and a sampling-offset of 1.
limg = gimg.downsample( [ 2, 2 ], [ 1, 1 ] )
# Display low-resolution image.
limg.show
# Apply element-wise function to each pixel of the image.
limg.collect { |x| x * x }
# Display processed image.
( limg.collect { |x| x * x } ).show
# Display range of values.
( limg.collect { |x| x * x } ).range
# Display range after normalisation.
( limg.collect { |x| x * x } ).normalise.range
# Display normalised result.
( limg.collect { |x| x * x } ).normalise.show
# Show data as one-dimensional array.
limg.data
# Define an element-wise function for one-dimensional arrays.
Sequence.define_unary_op( :sqr ) { |x| x * x }
# Reuse this function for multidimensional arrays.
MultiArray.define_unary_op( :sqr )
# Call the function.
limg.sqr
# Measure time of operation.
t = Time.new.to_f; limg.sqr; Time.new.to_f - t
# Example function using libJIT.
fun = JITFunction.compile( JITType::LINT, JITType::LINT ) do |f|
   ( JITTerm.param( f, 0 ) * JITTerm.const( f, JITType::LINT, 2 ) ).return_me
end
# Calling the function.
fun.call( 2 )
# Define element-wise operation using JIT.
Sequence.define_unary_jit_op( :sqr ) { |x| x * x }
# Measure time of operation now.
t = Time.new.to_f; limg.sqr; Time.new.to_f - t
# Apply function and display result.
gimg.sqr.normalise.show
# Apply function twice and display result.
gimg.sqr.sqr.normalise.show
# Define a small filter.
f = MultiArray.to_multiarray( [ [ -1, 0, 1 ], [ -2, 0, 2 ], [ -1, 0, 1 ] ] )
# Correlate with this filter (slow).
limg.correlate( f )
# Correlate with filter using native datatypes to facilitate the JIT-based implementation.
limg.correlate( f.to_sint )
# Sobel-X operator.
gimg.sobel_x
# Display Sobel-X and Sobel-Y image.
gimg.sobel_x.normalise.show
gimg.sobel_y.normalise.show
# Define an edge detector.
class MultiArray
  def edges
    Math.sqrt( sobel_x.sqr + sobel_y.sqr )
  end
end
# Compute edges.
gimg.edges
# Display edges.
gimg.edges.normalise.show
# Display edges black-on-white.
( 255 - gimg.edges.normalise ).show
# Same but more efficient.
gimg.edges.normalise( 255..0 ).show

See Also

External Links

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox