Added more functions to interface Gen programs
authorBenjamin Segovia <segovia.benjamin@gmail.com>
Wed, 21 Mar 2012 18:08:32 +0000 (18:08 +0000)
committerKeith Packard <keithp@keithp.com>
Fri, 10 Aug 2012 23:15:50 +0000 (16:15 -0700)
backend/src/gen/program.cpp
backend/src/gen/program.h
backend/src/gen/program.hpp

index 0795abd..d0e61ef 100644 (file)
@@ -147,13 +147,20 @@ uint32_t GenProgramGetKernelNum(const GenProgram *genProgram) {
 }
 
 GBE_EXPORT_SYMBOL
-const GenKernel *GenProgramGetKernel(const GenProgram *genProgram, const char *name) {
+const GenKernel *GenProgramGetKernelByName(const GenProgram *genProgram, const char *name) {
   if (genProgram == NULL) return NULL;
   const gbe::gen::Program *program = (const gbe::gen::Program*) genProgram;
   return (GenKernel*) program->getKernel(std::string(name));
 }
 
 GBE_EXPORT_SYMBOL
+const GenKernel *GenProgramGetKernel(const GenProgram *genProgram, uint32_t ID) {
+  if (genProgram == NULL) return NULL;
+  const gbe::gen::Program *program = (const gbe::gen::Program*) genProgram;
+  return (GenKernel*) program->getKernel(ID);
+}
+
+GBE_EXPORT_SYMBOL
 const char *GenKernelGetCode(const GenKernel *genKernel) {
   if (genKernel == NULL) return NULL;
   const gbe::gen::Kernel *kernel = (const gbe::gen::Kernel*) genKernel;
index 0a38995..97e4e71 100644 (file)
@@ -68,7 +68,10 @@ void GenProgramDelete(GenProgram *program);
 uint32_t GenProgramGetKernelNum(const GenProgram *program);
 
 /*! Get the kernel from its name */
-const GenKernel *GenProgramGetKernel(const GenProgram *program, const char *name);
+const GenKernel *GenProgramGetKernelByName(const GenProgram *program, const char *name);
+
+/*! Get the kernel from its ID */
+const GenKernel *GenProgramGetKernel(const GenProgram *program, uint32_t ID);
 
 /*! Get the Gen ISA source code */
 const char *GenKernelGetCode(const GenKernel *kernel);
index b117246..933529a 100644 (file)
@@ -105,6 +105,18 @@ namespace gen {
       else
         return it->second;
     }
+    /*! Get the kernel from its ID */
+    Kernel *getKernel(const uint32_t ID) const {
+      uint32_t currID = 0;
+      Kernel *kernel = NULL;
+      for (auto it = kernels.begin(); it != kernels.end(); ++it) {
+        if (currID == ID) {
+          kernel = it->second;
+          break;
+        }
+      }
+      return kernel;
+    }
     /*! Build a program from a ir::Unit */
     bool buildFromUnit(const ir::Unit &unit, std::string &error);
     /*! Buils a program from a LLVM source code */