[opengtl-commits] [234] * pass input images to evaluatePixel

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 234
Author:   cyrille
Date:     2008-06-25 21:46:48 +0200 (Wed, 25 Jun 2008)

Log Message:
-----------
* pass input images to evaluatePixel

Modified Paths:
--------------
    trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
    trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h
    trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h


Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-06-25 19:45:10 UTC (rev 233)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-06-25 19:46:48 UTC (rev 234)
@@ -25,6 +25,7 @@
 target_link_libraries(OpenShiva GTLCore )
 
 add_definitions( "${LLVM_COMPILE_FLAGS}")
+add_definitions( -DCOUMPONENT_NAME=\"\\\"OpenShiva\\\"\" )
 
 if (NOT APPLE)
   add_definitions( -D_OPENSHIVA_SHIVA_STD_LIB_BUILD_DIR_=\\"${CMAKE_CURRENT_BINARY_DIR}/../ShivaStdLib/\\")

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-06-25 19:45:10 UTC (rev 233)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp	2008-06-25 19:46:48 UTC (rev 234)
@@ -42,6 +42,7 @@
 #include "GTLCore/VariableNG_p.h"
 
 #include "Wrapper_p.h"
+#include "wrappers/ImageWrap_p.h"
 #include "wrappers/PixelWrap_p.h"
 
 #include "Debug.h"
@@ -216,42 +217,74 @@
     llvm::Value* arg_height = arg_it;
     //   void** _sources = fifth arg;
     ++arg_it;
-//     llvm::Value* arg_sources = arg_it;
+    llvm::Value* arg_sources = arg_it;
     //   void* _result = sixth arg;
     ++arg_it;
     llvm::Value* arg_result = arg_it;
   // Create the pixel
     GTLCore::VariableNG* resultVar = new GTLCore::VariableNG( _moduleData->typeManager()->getStructure( "pixel" ), false );
   resultVar->initialise( generationContext, initialBlock, 0, 0, std::list<llvm::Value*>());
+  // Get the evaluatePixel function
+    GTLCore::Function* ePFunction = _moduleData->function( _kernel->name(), "evaluatePixel" );
+    SHIVA_ASSERT( ePFunction );
+    unsigned int countArguments = ePFunction->parameters().size();
+    
+  // Create the list of parameters for the evaluatePixel function
+    std::vector<llvm::Value*> evaluatePixel_params;
+    for(unsigned int i = 0; i < countArguments - 1; ++i )
+    {
+      const GTLCore::Type* parameterType = ePFunction->parameters()[i].type();
+      // Allocate an ImageWrap structure
+      llvm::Value* val = new llvm::AllocaInst( parameterType->d->type(),
+                                               GTLCore::CodeGenerator::integerToConstant(1),
+                                               "", initialBlock);
+      // Add it to the list of parameters
+      evaluatePixel_params.push_back( val );
+      // Set the image field of the structure
+      std::vector<llvm::Value*> indexesImageWrap;
+      indexesImageWrap.push_back( generationContext.codeGenerator()->integerToConstant(0));
+      indexesImageWrap.push_back( generationContext.codeGenerator()->integerToConstant(ImageWrap::INDEX_IMAGE));
+      new llvm::StoreInst(
+            new llvm::LoadInst(
+              new llvm::GetElementPtrInst( arg_sources, GTLCore::CodeGenerator::integerToConstant( i ), "", initialBlock ),
+              "", initialBlock ),
+            new llvm::GetElementPtrInst( val, indexesImageWrap.begin(), indexesImageWrap.end(), "", initialBlock ),
+            "",
+            initialBlock );
+    }
+    evaluatePixel_params.push_back( resultVar->pointer() );
+    SHIVA_ASSERT( evaluatePixel_params.size() == countArguments );
   // Construct the "conditions" of the first loop
     // int j = 0;
     GTLCore::VariableNG* incJ = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
     incJ->initialise( generationContext, initialBlock,
                       arg_x,
                       GTLCore::Type::Integer32, std::list<llvm::Value*>());
+    
     // {
       llvm::BasicBlock* firstBlockJLoop = new llvm::BasicBlock;
       func->getBasicBlockList().push_back( firstBlockJLoop );
+      
       // int i = 0;
       GTLCore::VariableNG* incI = new GTLCore::VariableNG( GTLCore::Type::Integer32, false);
       incI->initialise( generationContext, firstBlockJLoop,
                         arg_y,
                         GTLCore::Type::Integer32, std::list<llvm::Value*>());
+      
       // {
         llvm::BasicBlock* firstBlockILoop = new llvm::BasicBlock;
         func->getBasicBlockList().push_back( firstBlockILoop );
         llvm::Value* jVal = incJ->get( generationContext, firstBlockILoop );
         llvm::Value* iVal = incI->get( generationContext, firstBlockILoop );
+        
         // Set the coordinates of the pixel
         setPixelCoordinates( generationContext, firstBlockILoop, resultVar->pointer(), iVal, jVal );
+        
         // Call evaluatePixel
-        GTLCore::Function* ePFunction = _moduleData->function( _kernel->name(), "evaluatePixel" );
-        SHIVA_ASSERT( ePFunction );
-        std::vector<llvm::Value*> evaluatePixel_params;
-        evaluatePixel_params.push_back( resultVar->pointer() );
-        llvm::Function* llvmEPFunction = ePFunction->d->data->function( 1 );
+        llvm::Function* llvmEPFunction = ePFunction->d->data->function( countArguments );
         SHIVA_ASSERT( llvmEPFunction );
         new llvm::CallInst( llvmEPFunction, evaluatePixel_params.begin(), evaluatePixel_params.end(), "", firstBlockILoop );
+        
         // Synchronize the output pixel with input
         // Call image_wrap_data on the result to get the pointer on destination data
         std::vector<llvm::Value*> image_wrap_data_params;
@@ -261,11 +294,14 @@
          llvm::Value* pointer =  new llvm::CallInst( Wrapper::image_wrap_dataFunction( _moduleData->llvmModule(), _moduleData->typeManager()->getStructure( "image" ) ), image_wrap_data_params.begin(), image_wrap_data_params.end(), "", firstBlockILoop );
         llvm::BasicBlock* lastBlockILoop = pixelToMem( generationContext, firstBlockILoop, resultVar->pointer(), pointer, _pixelDescription.bitsSize() / 8 );
       // }
+      
       llvm::BasicBlock* lastBlockJLoop = GTLCore::CodeGenerator::createIterationForStatement( generationContext, firstBlockJLoop, incI, arg_width, GTLCore::Type::Integer32, firstBlockILoop, lastBlockILoop);
     // }
+    
     llvm::BasicBlock* lastBlock = GTLCore::CodeGenerator::createIterationForStatement( generationContext, initialBlock, incJ, arg_height, GTLCore::Type::Integer32, firstBlockJLoop, lastBlockJLoop);
     new llvm::ReturnInst(lastBlock);
   // Cleanup
+  
   delete resultVar;
   delete incJ;
   delete incI;

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-06-25 19:45:10 UTC (rev 233)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.cpp	2008-06-25 19:46:48 UTC (rev 234)
@@ -167,11 +167,21 @@
 void Kernel::evaluatePixeles( const GTLCore::Region& _region, const std::list< AbstractImage* >& _inputImages, AbstractImage* _outputImage) const
 {
   SHIVA_ASSERT( d->evaluatePixelesFunction );
-  void (*func)( int, int, int, int, void**, void*) = ( void(*)(int, int, int, int, void**, void*))GTLCore::VirtualMachine::instance()->getPointerToFunction( d->evaluatePixelesFunction);
+  void (*func)( int, int, int, int, const void**, void*) = ( void(*)(int, int, int, int, const void**, void*))GTLCore::VirtualMachine::instance()->getPointerToFunction( d->evaluatePixelesFunction);
   SHIVA_ASSERT(func);
+  
+  const void** inputImages = new const void*[ _inputImages.size() ];
+  int i = 0;
+  for( std::list< AbstractImage* >::const_iterator it = _inputImages.begin();
+       it != _inputImages.end(); ++it)
+  {
+    inputImages[i] = (const void*)*it;
+  }
+  
   ImageWrap owrap;
   owrap.image = _outputImage;
-  (*func)( _region.x(), _region.y(), _region.width(), _region.height(), 0, (void*)&owrap); // TODO s/200/width s/300/height
+  (*func)( _region.x(), _region.y(), _region.width(), _region.height(), inputImages, (void*)&owrap); // TODO s/200/width s/300/height
+  delete[] inputImages;
 }
 
 int Kernel::runTest() const

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h	2008-06-25 19:45:10 UTC (rev 233)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Kernel.h	2008-06-25 19:46:48 UTC (rev 234)
@@ -34,6 +34,9 @@
 namespace OpenShiva {
   class AbstractImage;
   /**
+   * This is the main class in OpenShiva, it is used to compile the kernel, and to apply it on
+   * a set of images.
+   * 
    * @ingroup OpenShiva
    */
   class Kernel {

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp	2008-06-25 19:45:10 UTC (rev 233)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/PixelVisitor_p.cpp	2008-06-25 19:46:48 UTC (rev 234)
@@ -22,6 +22,7 @@
 // LLVM
 #include <llvm/Instructions.h>
 
+#include "GTLCore/Macros_p.h"
 #include "GTLCore/Type.h"
 
 #include "Debug.h"

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp	2008-06-25 19:45:10 UTC (rev 233)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp	2008-06-25 19:46:48 UTC (rev 234)
@@ -27,6 +27,7 @@
 
 #include "GTLCore/Function_p.h"
 #include "GTLCore/Macros.h"
+#include "GTLCore/Macros_p.h"
 #include "GTLCore/Parameter.h"
 #include "GTLCore/PixelDescription.h"
 #include "GTLCore/Type.h"
@@ -158,7 +159,7 @@
   functionArgs.push_back(llvm::IntegerType::get(32));
   functionArgs.push_back(llvm::IntegerType::get(32));
   llvm::FunctionType* functionTy = llvm::FunctionType::get( llvm::PointerType::get(llvm::IntegerType::get(8), 0), functionArgs, false);
-  GTL_DEBUG( *functionTy );
+  SHIVA_DEBUG( *functionTy );
   return new llvm::Function( functionTy, llvm::GlobalValue::ExternalLinkage, "image_wrap_data", _module);
 }
 

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h	2008-06-25 19:45:10 UTC (rev 233)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/ImageWrap_p.h	2008-06-25 19:46:48 UTC (rev 234)
@@ -31,6 +31,9 @@
 //---------------------- WARNING ----------------------//
 struct ImageWrap {
   OpenShiva::AbstractImage* image;
+  enum ImageIndexes {
+    INDEX_IMAGE = 0,
+  };
 };
 
 extern "C" {


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/