@@ -128,10 +128,9 @@ struct Kernel {
128128
129129 explicit Kernel (cl_program program, cl_kernel kernel, const size_t *gridSize,
130130 const size_t *blockSize, size_t argNum, const size_t *argSize)
131- : program(program),
132- kernel(kernel), globalSize{gridSize[0 ] * blockSize[0 ],
133- gridSize[1 ] * blockSize[1 ],
134- gridSize[2 ] * blockSize[2 ]},
131+ : program(program), kernel(kernel),
132+ globalSize{gridSize[0 ] * blockSize[0 ], gridSize[1 ] * blockSize[1 ],
133+ gridSize[2 ] * blockSize[2 ]},
135134 localSize{blockSize[0 ], blockSize[1 ], blockSize[2 ]},
136135 argSize (argSize, argSize + argNum) {
137136#ifndef NDEBUG
@@ -817,7 +816,7 @@ ArrayRef<Type> getArgTypes(const StringRef &funcName, ModuleOp &mod) {
817816
818817OclModuleBuilder::OclModuleBuilder (ModuleOp module ,
819818 const OclModuleBuilderOpts &opts)
820- : mlirModule(module ), printIr(opts.printIr),
819+ : mlirModule(module ), printIr(opts.printIr), spirvDump(opts.spirvDump),
821820 enableObjectDump (opts.enableObjectDump),
822821 sharedLibPaths(opts.sharedLibPaths),
823822 pipeline(opts.pipeline
@@ -993,6 +992,43 @@ OclModuleBuilder::build(const OclRuntime::Ext &ext) {
993992 mod.dump ();
994993 }
995994
995+ if (spirvDump) {
996+ mod->walk ([&](LLVM::GlobalOp global) {
997+ auto isaKernel = [&](LLVM::GlobalOp op) {
998+ return op.getName ().starts_with (" gcGpuOclKernel_" ) &&
999+ op.getName ().ends_with (" SPIRV" );
1000+ };
1001+
1002+ if (!isaKernel (global))
1003+ return WalkResult::skip ();
1004+
1005+ auto name = global.getName ();
1006+ gcLogD (" Found a kernel to dump (" , name.str (), " )" );
1007+
1008+ std::error_code ec;
1009+ std::string filename = " GC_" + name.str () + " .spv" ;
1010+ llvm::raw_fd_ostream spvStream (filename, ec);
1011+ if (ec) {
1012+ gcLogE (" Failed to create a file `" , filename,
1013+ " `, error message: " , ec.message ());
1014+ return WalkResult::skip ();
1015+ }
1016+
1017+ auto val = global.getValue ();
1018+ assert (val && " unexpected empty kernel" );
1019+ auto string = llvm::cast<mlir::StringAttr>(*val);
1020+ spvStream.write (string.data (), string.size ());
1021+
1022+ if (spvStream.has_error ()) {
1023+ gcLogE (" An error occured while writing to `" , filename, " `." );
1024+ return WalkResult::skip ();
1025+ }
1026+
1027+ spvStream.flush ();
1028+ return WalkResult::skip ();
1029+ });
1030+ }
1031+
9961032 OclModule::MainFunc main = {nullptr };
9971033
9981034 if (staticMain.empty ()) {
0 commit comments