[Mesa-dev] [PATCH 2/3] clover: Handle multiple kernels in the same program

Tom Stellard tom at stellard.net
Thu Sep 13 13:41:55 PDT 2012


From: Blaž Tomažič <blaz.tomazic at gmail.com>

---
 src/gallium/state_trackers/clover/core/kernel.cpp  |  1 +
 .../state_trackers/clover/llvm/invocation.cpp      | 66 +++++++++++-----------
 2 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/src/gallium/state_trackers/clover/core/kernel.cpp b/src/gallium/state_trackers/clover/core/kernel.cpp
index 6fa8bd6..7f1a158 100644
--- a/src/gallium/state_trackers/clover/core/kernel.cpp
+++ b/src/gallium/state_trackers/clover/core/kernel.cpp
@@ -156,6 +156,7 @@ _cl_kernel::exec_context::bind(clover::command_queue *__q) {
       cs.prog = kern.module(*q).sec(module::section::text).data.begin();
       cs.req_local_mem = mem_local;
       cs.req_input_mem = input.size();
+      cs.entry_symbol = kern.name().data();
       st = q->pipe->create_compute_state(q->pipe, &cs);
    }
 
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index be15e96..115c38d 100644
--- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
+++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
@@ -199,41 +199,42 @@ namespace {
       llvm::WriteBitcodeToFile(mod, bitcode_ostream);
       bitcode_ostream.flush();
 
-      llvm::Function *kernel_func;
-      std::string kernel_name;
-      compat::vector<module::argument> args;
-
-      // XXX: Support more than one kernel
-      assert(kernels.size() == 1);
-
-      kernel_func = kernels[0];
-      kernel_name = kernel_func->getName();
-
-      for (llvm::Function::arg_iterator I = kernel_func->arg_begin(),
-                                   E = kernel_func->arg_end(); I != E; ++I) {
-         llvm::Argument &arg = *I;
-         llvm::Type *arg_type = arg.getType();
-         llvm::TargetData TD(kernel_func->getParent());
-         unsigned arg_size = TD.getTypeStoreSize(arg_type);
-
-         if (llvm::isa<llvm::PointerType>(arg_type) && arg.hasByValAttr()) {
-            arg_type =
-               llvm::dyn_cast<llvm::PointerType>(arg_type)->getElementType();
-         }
+      for (unsigned i = 0; i < kernels.size(); ++i) {
+         llvm::Function *kernel_func;
+         std::string kernel_name;
+         compat::vector<module::argument> args;
+
+         kernel_func = kernels[i];
+         kernel_name = kernel_func->getName();
+
+         for (llvm::Function::arg_iterator I = kernel_func->arg_begin(),
+                                      E = kernel_func->arg_end(); I != E; ++I) {
+            llvm::Argument &arg = *I;
+            llvm::Type *arg_type = arg.getType();
+            llvm::TargetData TD(kernel_func->getParent());
+            unsigned arg_size = TD.getTypeStoreSize(arg_type);
+
+            if (llvm::isa<llvm::PointerType>(arg_type) && arg.hasByValAttr()) {
+               arg_type =
+                  llvm::dyn_cast<llvm::PointerType>(arg_type)->getElementType();
+            }
 
-         if (arg_type->isPointerTy()) {
-            // XXX: Figure out LLVM->OpenCL address space mappings for each
-            // target.  I think we need to ask clang what these are.  For now,
-            // pretend everything is in the global address space.
-            unsigned address_space = llvm::cast<llvm::PointerType>(arg_type)->getAddressSpace();
-            switch (address_space) {
-               default:
-                  args.push_back(module::argument(module::argument::global, arg_size));
-                  break;
+            if (arg_type->isPointerTy()) {
+               // XXX: Figure out LLVM->OpenCL address space mappings for each
+               // target.  I think we need to ask clang what these are.  For now,
+               // pretend everything is in the global address space.
+               unsigned address_space = llvm::cast<llvm::PointerType>(arg_type)->getAddressSpace();
+               switch (address_space) {
+                  default:
+                     args.push_back(module::argument(module::argument::global, arg_size));
+                     break;
+               }
+            } else {
+               args.push_back(module::argument(module::argument::scalar, arg_size));
             }
-         } else {
-            args.push_back(module::argument(module::argument::scalar, arg_size));
          }
+
+         m.syms.push_back(module::symbol(kernel_name, 0, 0, args ));
       }
 
       header.num_bytes = llvm_bitcode.size();
@@ -241,7 +242,6 @@ namespace {
       data.insert(0, (char*)(&header), sizeof(header));
       data.insert(data.end(), llvm_bitcode.begin(),
                                   llvm_bitcode.end());
-      m.syms.push_back(module::symbol(kernel_name, 0, 0, args ));
       m.secs.push_back(module::section(0, module::section::text,
                                        header.num_bytes, data));
 
-- 
1.7.11.4



More information about the mesa-dev mailing list