Commit 7e0180d5 authored by Serge Martin's avatar Serge Martin Committed by Francisco Jerez
Browse files

clover: little OpenCL status code logging clean



s/build_error/compile_error in order to match the stored OpenCL status code.
Make program::build catch and log every OpenCL error.
Make tgsi error triggering uniform with the llvm one.
Reviewed-by: Francisco Jerez's avatarFrancisco Jerez <currojerez@riseup.net>
parent 7b9ebf87
......@@ -37,7 +37,8 @@ namespace clover {
const std::string &opts,
std::string &r_log);
module compile_program_tgsi(const std::string &source);
module compile_program_tgsi(const std::string &source,
std::string &r_log);
}
#endif
......@@ -65,9 +65,9 @@ namespace clover {
cl_int code;
};
class build_error : public error {
class compile_error : public error {
public:
build_error(const std::string &what = "") :
compile_error(const std::string &what = "") :
error(CL_COMPILE_PROGRAM_FAILURE, what) {
}
};
......
......@@ -56,14 +56,14 @@ program::build(const ref_vector<device> &devs, const char *opts,
try {
auto module = (dev.ir_format() == PIPE_SHADER_IR_TGSI ?
compile_program_tgsi(_source) :
compile_program_tgsi(_source, log) :
compile_program_llvm(_source, headers,
dev.ir_format(),
dev.ir_target(), build_opts(dev),
log));
_binaries.insert({ &dev, module });
_logs.insert({ &dev, log });
} catch (const build_error &) {
} catch (const error &) {
_logs.insert({ &dev, log });
throw;
}
......
......@@ -108,7 +108,7 @@ namespace {
name, llvm::MemoryBuffer::getMemBuffer(source));
if (!c.ExecuteAction(act))
throw build_error(log);
throw compile_error(log);
}
module
......@@ -256,7 +256,7 @@ namespace {
r_log = log;
if (!ExecSuccess)
throw build_error();
throw compile_error();
// Get address spaces map to be able to find kernel argument address space
memcpy(address_spaces, c.getTarget().getAddressSpaceMap(),
......@@ -485,7 +485,7 @@ namespace {
LLVMDisposeMessage(err_message);
if (err) {
throw build_error();
throw compile_error();
}
}
......@@ -505,7 +505,7 @@ namespace {
if (LLVMGetTargetFromTriple(triple.c_str(), &target, &error_message)) {
r_log = std::string(error_message);
LLVMDisposeMessage(error_message);
throw build_error();
throw compile_error();
}
LLVMTargetMachineRef tm = LLVMCreateTargetMachine(
......@@ -514,7 +514,7 @@ namespace {
if (!tm) {
r_log = "Could not create TargetMachine: " + triple;
throw build_error();
throw compile_error();
}
if (dump_asm) {
......@@ -567,7 +567,7 @@ namespace {
const char *name;
if (gelf_getshdr(section, &symtab_header) != &symtab_header) {
r_log = "Failed to read ELF section header.";
throw build_error();
throw compile_error();
}
name = elf_strptr(elf, section_str_index, symtab_header.sh_name);
if (!strcmp(name, ".symtab")) {
......@@ -577,9 +577,9 @@ namespace {
}
if (!symtab) {
r_log = "Unable to find symbol table.";
throw build_error();
throw compile_error();
}
} catch (build_error &e) {
} catch (compile_error &e) {
elf_end(elf);
throw e;
}
......@@ -650,7 +650,7 @@ namespace {
stream.flush();
*(std::string*)data = message;
throw build_error();
throw compile_error();
}
}
......
......@@ -32,7 +32,7 @@ using namespace clover;
namespace {
void
read_header(const std::string &header, module &m) {
read_header(const std::string &header, module &m, std::string &r_log) {
std::istringstream ls(header);
std::string line;
......@@ -45,8 +45,10 @@ namespace {
if (!(ts >> name))
continue;
if (!(ts >> offset))
throw build_error("invalid kernel start address");
if (!(ts >> offset)) {
r_log = "invalid kernel start address";
throw compile_error();
}
while (ts >> tok) {
if (tok == "scalar")
......@@ -67,8 +69,10 @@ namespace {
args.push_back({ module::argument::image3d_wr, 4 });
else if (tok == "sampler")
args.push_back({ module::argument::sampler, 0 });
else
throw build_error("invalid kernel argument");
else {
r_log = "invalid kernel argument";
throw compile_error();
}
}
m.syms.push_back({ name, 0, offset, args });
......@@ -76,11 +80,13 @@ namespace {
}
void
read_body(const char *source, module &m) {
read_body(const char *source, module &m, std::string &r_log) {
tgsi_token prog[1024];
if (!tgsi_text_translate(source, prog, Elements(prog)))
throw build_error("translate failed");
if (!tgsi_text_translate(source, prog, Elements(prog))) {
r_log = "translate failed";
throw compile_error();
}
unsigned sz = tgsi_num_tokens(prog) * sizeof(tgsi_token);
std::vector<char> data( (char *)prog, (char *)prog + sz );
......@@ -89,13 +95,13 @@ namespace {
}
module
clover::compile_program_tgsi(const std::string &source) {
clover::compile_program_tgsi(const std::string &source, std::string &r_log) {
const size_t body_pos = source.find("COMP\n");
const char *body = &source[body_pos];
module m;
read_header({ source.begin(), source.begin() + body_pos }, m);
read_body(body, m);
read_header({ source.begin(), source.begin() + body_pos }, m, r_log);
read_body(body, m, r_log);
return m;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment