[Beignet] [PATCH V3 2/3] add [opencl-1.2] API clLinkProgram.

Song, Ruiling ruiling.song at intel.com
Thu Jun 5 20:00:41 PDT 2014


+      if (errMsg.c_str() != NULL) {
+        if (err != NULL && errSize != NULL && stringSize > 0u) {
+          if(errMsg.length() < stringSize )
+            stringSize = errMsg.length();
+          strcpy(err, errMsg.c_str());
+          err[stringSize+1] = '\0';
+        }
+      }
+      printf("%s\n", err);
>>> please remove this print.
+    }
+    // Everything run fine
+#endif
+  }
+
+  static void genProgramBuildFromLLVM(gbe_program program,
+                                      size_t stringSize,
+                                      char *err,
+                                      size_t *errSize,
+                                      const char *          options)
+  {
+#ifdef GBE_COMPILER_AVAILABLE
+    using namespace gbe;
+    std::string error;
+
+    int optLevel = 1;
+
+    if(options) {
+      char *p;
+      p = strstr(const_cast<char *>(options), "-cl-opt-disable");
+      if (p)
+        optLevel = 0;
+    }
+
+    GenProgram* p = (GenProgram*) program;
+    // Try to compile the program
+    static std::mutex gbe_mutex;
+    gbe_mutex.lock();
+    llvm::Module* module = (llvm::Module*)p->module;
+
+    if (p->buildFromLLVMFile(NULL, module, error, optLevel) == false) {
+      if (err != NULL && errSize != NULL && stringSize > 0u) {
+        const size_t msgSize = std::min(error.size(), stringSize-1u);
+        std::memcpy(err, error.c_str(), msgSize);
+        *errSize = error.size();
+      }
+      gbe_mutex.unlock();
>>> the mutex lock & unlock should be correctly matched.
+      GBE_DELETE(p);
+    }
+#endif
+  }
+
 } /* namespace gbe */
 
 void genSetupCallBacks(void)
@@ -239,4 +331,7 @@ void genSetupCallBacks(void)
   gbe_program_new_from_binary = gbe::genProgramNewFromBinary;
   gbe_program_serialize_to_binary = gbe::genProgramSerializeToBinary;
   gbe_program_new_from_llvm = gbe::genProgramNewFromLLVM;
+  gbe_program_new_gen_program = gbe::genProgramNewGenProgram;  
+ gbe_program_link_from_llvm = gbe::genProgramLinkFromLLVM;  
+ gbe_program_build_from_llvm = gbe::genProgramBuildFromLLVM;
 }
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp index 7cfc07e..4bcc560 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -980,18 +980,14 @@ namespace gbe {
     if (buildModuleFromSource(clName.c_str(), &out_module, llvm_ctx, clOpt.c_str(),
                               stringSize, err, errSize)) {
     // Now build the program from llvm
-      size_t clangErrSize = 0;
       if (err != NULL) {
         GBE_ASSERT(errSize != NULL);
         stringSize -= *errSize;
         err += *errSize;
-        clangErrSize = *errSize;
       }
 
       p = gbe_program_new_gen_program(deviceID, out_module, NULL);
 
-      if (err != NULL)
-        *errSize += clangErrSize;
       if (OCL_OUTPUT_BUILD_LOG && options)
         llvm::errs() << options;
     } else
@@ -1002,6 +998,25 @@ namespace gbe {
   }
 #endif
 
+#ifdef GBE_COMPILER_AVAILABLE
+  static void programLinkProgram(gbe_program           dst_program,
+                                 gbe_program           src_program,
+                                 size_t                stringSize,
+                                 char *                err,
+                                 size_t *              errSize)
+  {
+    static std::mutex gbe_mutex;
+    gbe_mutex.lock();
>>> I think use a function scope mutex could reach your goal. You need to use SAME mutex to protect the GlobalContext among compile, link , llvmToGen.
+    gbe_program_link_from_llvm(dst_program, src_program, stringSize, 
+ err, errSize);
+
+    gbe_mutex.unlock();
+
+    if (OCL_OUTPUT_BUILD_LOG && err)
+      llvm::errs() << err;
+  }
+#endif

 error:
-  p->is_built = 1;
>>> I think if a program is clBuild, clCompile, clink, is_built need to be set as 1. Please check ocl spec.
+  cl_program_delete(p);
+  p = NULL;
   return err;
 }
 
diff --git a/src/cl_program.h b/src/cl_program.h index a576d37..49a4f48 100644
--- a/src/cl_program.h
+++ b/src/cl_program.h
@@ -117,5 +117,12 @@ cl_program_compile(cl_program            p,
                    const cl_program *    input_headers,
                    const char **         header_include_names,
                    const char*           options);
+/* link the program as specified by OCL */ extern cl_program
+cl_program_link(cl_context            context,
+                cl_uint               num_input_programs,
+                const cl_program *    input_programs,
+                const char *          options,
+                cl_int*               errcode_ret);
 #endif /* __CL_PROGRAM_H__ */
 
--
1.8.1.2

_______________________________________________
Beignet mailing list
Beignet at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list