Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TVM] Fixed SPIR-V codegen incorrectly not declaring the interface for the entry point #1400

Merged
merged 6 commits into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/codegen/spirv/codegen_spirv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ std::vector<uint32_t> CodeGenSPIRV::BuildFunction(const LoweredFunc& f) {
pod_args.push_back(arg);
}
}
spirv::Value func_ptr = builder_->DeclareKenrelFunction(f->name);
spirv::Value func_ptr = builder_->NewFunction();
builder_->StartFunction(func_ptr);

// All the POD arguments are passed in through PushConstant
Expand All @@ -56,6 +56,8 @@ std::vector<uint32_t> CodeGenSPIRV::BuildFunction(const LoweredFunc& f) {
builder_->MakeInst(spv::OpReturn);
builder_->MakeInst(spv::OpFunctionEnd);

builder_->CommitKernelFunction(func_ptr, f->name);

return builder_->Finalize();
}

Expand Down
19 changes: 14 additions & 5 deletions src/codegen/spirv/ir_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,21 @@ Value IRBuilder::GetPushConstant(
return this->MakeValue(spv::OpLoad, v_type, ptr);
}

Value IRBuilder::DeclareKenrelFunction(const std::string& name) {
Value val = NewValue(t_void_func_, kFunction);
Value IRBuilder::NewFunction() {
return NewValue(t_void_func_, kFunction);
}

void IRBuilder::CommitKernelFunction(const Value& func, const std::string& name) {
CHECK_EQ(func.flag, kFunction);
ib_.Begin(spv::OpEntryPoint)
.AddSeq(spv::ExecutionModelGLCompute, val, name)
.Commit(&entry_);
return val;
.AddSeq(spv::ExecutionModelGLCompute, func, name);
if (workgroup_id_.id != 0) {
ib_.Add(workgroup_id_);
}
if (local_id_.id != 0) {
ib_.Add(local_id_);
}
ib_.Commit(&entry_);
}

void IRBuilder::StartFunction(const Value& func) {
Expand Down
13 changes: 10 additions & 3 deletions src/codegen/spirv/ir_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,18 @@ class IRBuilder {
*/
Value GetPushConstant(Value ptr_push_const, const SType& v_type, uint32_t index);
/*!
* \brief Declare a kernel function
* \param name Name of the entry point.
* \brief Declare a new function
* \return The created function ID.
*/
Value DeclareKenrelFunction(const std::string& name);
Value NewFunction();
/*!
* \brief Declare the entry point for a kernel function. This should be
* invoked after building the function so the builder is aware of which
* variables to declare as part of the function's interface.
* \param func The previously declared function.
* \param name Name of the entry point.
*/
void CommitKernelFunction(const Value& func, const std::string& name);
/*!
* \brief Start function scope.
* \param func function to be started.
Expand Down