Skip to content

Commit

Permalink
Some fixes according to review.
Browse files Browse the repository at this point in the history
  • Loading branch information
phisiart committed Dec 15, 2017
1 parent d62f3bd commit 26bba41
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 41 deletions.
3 changes: 2 additions & 1 deletion include/tvm/runtime/c_runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ typedef int64_t tvm_index_t;

/*! \brief Extension device types in TVM */
typedef enum {
kOpenGL = 11,

// Extension DRAM type, used for quickly test extension device
// The device api can differ depending on the xpu driver registered.
kExtDev = 12,
// AddExtraTVMType which is not in DLPack here
kOpenGL = 11,
} TVMDeviceExtType;

/*!
Expand Down
5 changes: 2 additions & 3 deletions python/tvm/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ def __init__(self,
elif target_name in ("metal",):
self.keys += ("gpu",)
self.max_num_threads = 256
elif target_name in ("opengl"):
# TODO(zhixunt): What here?
pass
elif target_name in ("opengl",):
self.keys += ("opengl",)
elif target_name in ("stackvm", "ext_dev"):
# Do not now class for stacvm or ext_dev
pass
Expand Down
17 changes: 10 additions & 7 deletions src/codegen/codegen_opengl.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/*!
* Copyright (c) 2017 by Contributors
* \file codegen_opengl.cc
*
* We are targeting OpenGL 3.3. The reason of not targeting a recent version
* of OpenGL is to have better compatibility of WebGL 2.
*/
#include <tvm/runtime/config.h>
#include <tvm/packed_func_ext.h>
Expand All @@ -14,11 +17,11 @@ namespace codegen {

CodeGenOpenGL::CodeGenOpenGL() : output_(nullptr), iter_var_(nullptr) {
// TODO(zhixunt): Implement this.
LOG_INFO.stream() << "CodeGenOpenGL::CodeGenOpenGL";
LOG(INFO) << "CodeGenOpenGL::CodeGenOpenGL";
}

void CodeGenOpenGL::AddFunction(LoweredFunc f) {
LOG_INFO.stream() << "CodeGenOpenGL::AddFunction";
LOG(INFO) << "CodeGenOpenGL::AddFunction";

this->stream << "#version 330 core\n";

Expand All @@ -33,7 +36,7 @@ void CodeGenOpenGL::AddFunction(LoweredFunc f) {

// Allocate argument names.
for (Var arg : f->args) {
LOG_INFO.stream() << "Arg: " << arg.get()->name_hint;
LOG(INFO) << "Arg: " << arg.get()->name_hint;
AllocVarID(arg.get());
}

Expand All @@ -56,7 +59,7 @@ void CodeGenOpenGL::AddFunction(LoweredFunc f) {
}

void CodeGenOpenGL::BindThreadIndex(const IterVar& iv) {
LOG_INFO.stream() << "CodeGenOpenGL::BindThreadIndex";
LOG(INFO) << "CodeGenOpenGL::BindThreadIndex";
CHECK(!var_idmap_.count(iv->var.get()));

// TODO(zhixunt): Can we not hardcode the name?
Expand All @@ -70,7 +73,7 @@ void CodeGenOpenGL::BindThreadIndex(const IterVar& iv) {
}

void CodeGenOpenGL::VisitStmt_(const Store* op) {
LOG_INFO.stream() << "CodeGenOpenGL::VisitStmt_(const Store *)";
LOG(INFO) << "CodeGenOpenGL::VisitStmt_(const Store *)";
Type t = op->value.type();
if (t.lanes() == 1) {
// Store to a scalar.
Expand All @@ -82,7 +85,7 @@ void CodeGenOpenGL::VisitStmt_(const Store* op) {

} else {
// Store to an array.
LOG_FATAL.stream() << "Storing to an array not implemented";
LOG(FATAL) << "Storing to an array not implemented";
}
}

Expand Down Expand Up @@ -131,7 +134,7 @@ void CodeGenOpenGL::VisitExpr_(const FloatImm* op, std::ostream& os) {
}

void CodeGenOpenGL::VisitExpr_(const StringImm*, std::ostream& os) {
LOG_FATAL.stream() << "GLSL 3.3 doesn't support strings.";
LOG(FATAL) << "GLSL 3.3 doesn't support strings.";
}

} // namespace tvm
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/opengl/opengl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ namespace tvm {
namespace runtime {
namespace gl {

// This file contains the following classes.
class OpenGLWorkspace;
class Texture;

class Program;

/*!
Expand Down
44 changes: 22 additions & 22 deletions src/runtime/opengl/opengl_device_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void OPENGL_CHECK_ERROR() {
}

void GlfwErrorCallback(int err, const char* str) {
LOG_ERROR.stream() << "Error: [" << err << "] " << str;
LOG(ERROR) << "Error: [" << err << "] " << str;
}

// Always only use the first dimension of a 2D texture.
Expand All @@ -59,7 +59,7 @@ Texture::Texture(size_t nbytes)
: texture_(kInvalidTexture),
width_(static_cast<decltype(width_)>(nbytes / sizeof(GLfloat))),
height_(1) {
LOG_INFO.stream() << "Created texture [" << texture_ << "]";
LOG(INFO) << "Created texture [" << texture_ << "]";
CHECK((nbytes % sizeof(GLfloat)) == 0) << "Must be multiple of GLfloats";

// Create a texture.
Expand Down Expand Up @@ -87,7 +87,7 @@ Texture::Texture(size_t nbytes)

Texture::~Texture() {
if (texture_ != kInvalidTexture) {
LOG_INFO.stream() << "Deleting texture [" << texture_ << "]";
LOG(INFO) << "Deleting texture [" << texture_ << "]";

OPENGL_CALL(glDeleteTextures(1, &texture_));
texture_ = kInvalidTexture;
Expand All @@ -103,7 +103,7 @@ void Texture::GetData(GLvoid* data) const {
}

void Texture::PutData(GLint begin, GLsizei nelems, const GLvoid* data) {
LOG_INFO.stream() << "Texture::PutData(" << "begin = " << begin << ", "
LOG(INFO) << "Texture::PutData(" << "begin = " << begin << ", "
<< "nelems = " << nelems << ", data)";

// Bind to temporary unit.
Expand Down Expand Up @@ -131,25 +131,25 @@ const std::shared_ptr<OpenGLWorkspace>& OpenGLWorkspace::Global() {

void OpenGLWorkspace::SetDevice(TVMContext ctx) {
// TODO(zhixunt): Implement this.
LOG_INFO.stream() << "OpenGLWorkspace::SetDevice";
LOG(INFO) << "OpenGLWorkspace::SetDevice";
}

void OpenGLWorkspace::GetAttr(
TVMContext ctx, DeviceAttrKind kind, TVMRetValue* rv) {
// TODO(zhixunt): Implement this.
LOG_INFO.stream() << "OpenGLWorkspace::GetAttr";
LOG(INFO) << "OpenGLWorkspace::GetAttr";
}

void* OpenGLWorkspace::AllocDataSpace(
TVMContext ctx, size_t nbytes, size_t alignment) {
LOG_INFO.stream()
LOG(INFO)
<< "OpenGLWorkspace::AllocDataSpace(ctx, nbytes = "
<< nbytes << ", alignment = " << alignment << ")";
return reinterpret_cast<void*>(new Texture(nbytes));
}

void OpenGLWorkspace::FreeDataSpace(TVMContext ctx, void* ptr) {
LOG_INFO.stream()
LOG(INFO)
<< "OpenGLWorkspace::FreeDataSpace(ctx, ptr = "
<< ptr << ")";
delete reinterpret_cast<Texture*>(ptr);
Expand All @@ -163,7 +163,7 @@ void OpenGLWorkspace::CopyDataFromTo(const void* from,
TVMContext ctx_from,
TVMContext ctx_to,
TVMStreamHandle stream) {
LOG_INFO.stream()
LOG(INFO)
<< "OpenGLWorkspace::CopyDataFromTo("
<< "from = " << from << ", "
<< "from_offset = " << from_offset << ", "
Expand All @@ -184,7 +184,7 @@ void OpenGLWorkspace::CopyDataFromTo(const void* from,
// OpenGL texture => OpenGL texture

// TODO(pengw): Implement this.
LOG_FATAL.stream() << "Not Implemented";
LOG(FATAL) << "Not Implemented";

} else if (ctx_from.device_type == gl_devtype &&
ctx_to.device_type == kDLCPU) {
Expand Down Expand Up @@ -217,18 +217,18 @@ void OpenGLWorkspace::CopyDataFromTo(const void* from,

void OpenGLWorkspace::StreamSync(TVMContext ctx, TVMStreamHandle stream) {
// TODO(zhixunt): Implement this.
LOG_INFO.stream() << "OpenGLWorkspace::StreamSync";
LOG(INFO) << "OpenGLWorkspace::StreamSync";
}

void* OpenGLWorkspace::AllocWorkspace(TVMContext ctx, size_t size) {
// TODO(zhixunt): Implement this.
LOG_INFO.stream() << "OpenGLWorkspace::AllocWorkspace";
LOG(INFO) << "OpenGLWorkspace::AllocWorkspace";
return nullptr;
}

void OpenGLWorkspace::FreeWorkspace(TVMContext ctx, void* data) {
// TODO(zhixunt): Implement this.
LOG_INFO.stream() << "OpenGLWorkspace::FreeWorkspace";
LOG(INFO) << "OpenGLWorkspace::FreeWorkspace";
}

OpenGLWorkspace::OpenGLWorkspace() {
Expand All @@ -238,7 +238,7 @@ OpenGLWorkspace::OpenGLWorkspace() {

// Initialize GLFW.
if (glfwInit() != GL_TRUE) {
LOG_ERROR.stream() << "glfwInit() failed!";
LOG(ERROR) << "glfwInit() failed!";
assert(false);
}

Expand All @@ -250,11 +250,11 @@ OpenGLWorkspace::OpenGLWorkspace() {
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
window_ = glfwCreateWindow(kWindowWidth, kWindowHeight, "", nullptr, nullptr);
if (window_ == nullptr) {
LOG_ERROR.stream() << "glfwCreateWindow() failed!";
LOG(ERROR) << "glfwCreateWindow() failed!";
assert(false);
}

LOG_INFO.stream() << "GLFW says OpenGL version: "
LOG(INFO) << "GLFW says OpenGL version: "
<< glfwGetWindowAttrib(window_, GLFW_CONTEXT_VERSION_MAJOR)
<< "."
<< glfwGetWindowAttrib(window_, GLFW_CONTEXT_VERSION_MINOR)
Expand All @@ -267,7 +267,7 @@ OpenGLWorkspace::OpenGLWorkspace() {
// Must be called after creating GLFW window.
gladLoadGL();

LOG_INFO.stream() << "OpenGL says version: " << glGetString(GL_VERSION);
LOG(INFO) << "OpenGL says version: " << glGetString(GL_VERSION);

OPENGL_CHECK_ERROR();

Expand All @@ -288,7 +288,7 @@ OpenGLWorkspace::OpenGLWorkspace() {
}

OpenGLWorkspace::~OpenGLWorkspace() {
LOG_INFO.stream() << "~OpenGLWorkspace()";
LOG(INFO) << "~OpenGLWorkspace()";
// Paired with glfwCreateWindow().
glfwDestroyWindow(window_);
// Paired with glfwInit().
Expand Down Expand Up @@ -355,7 +355,7 @@ GLuint OpenGLWorkspace::CreateShader(GLenum shader_kind,
if (info_log_len > 0) {
std::unique_ptr<char[]> err_msg(new char[info_log_len + 1]);
glGetShaderInfoLog(shader, info_log_len, nullptr, err_msg.get());
LOG_ERROR.stream() << err_msg.get();
LOG(ERROR) << err_msg.get();
assert(false);
}

Expand All @@ -382,7 +382,7 @@ std::unique_ptr<Program> OpenGLWorkspace::CreateProgram(
if (info_log_len > 0) {
std::unique_ptr<char[]> err_msg(new char[info_log_len + 1]);
glGetProgramInfoLog(program, info_log_len, nullptr, err_msg.get());
LOG_ERROR.stream() << err_msg.get();
LOG(ERROR) << err_msg.get();
assert(false);
}

Expand All @@ -405,7 +405,7 @@ void OpenGLWorkspace::Render(
const std::vector<std::pair<std::string, Texture*>>& inputs,
Texture* output) {
if (inputs.size() + 2 > NumTextureUnits()) {
LOG_ERROR.stream() << "Too many inputs!";
LOG(ERROR) << "Too many inputs!";
assert(false);
}

Expand All @@ -427,7 +427,7 @@ void OpenGLWorkspace::Render(

// Always check that our framebuffer is ok
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
LOG_ERROR.stream() << "Framebuffer not complete.";
LOG(ERROR) << "Framebuffer not complete.";
assert(false);
}

Expand Down
14 changes: 7 additions & 7 deletions src/runtime/opengl/opengl_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ OpenGLModuleNode::OpenGLModuleNode(
std::unordered_map<std::string, FunctionInfo> fmap)
: workspace_(gl::OpenGLWorkspace::Global()), data_(std::move(data)),
fmt_(std::move(fmt)), fmap_(std::move(fmap)) {
LOG_INFO.stream() << "OpenGLModuleNode(" << data << ", " << fmt << ", "
LOG(INFO) << "OpenGLModuleNode(" << data << ", " << fmt << ", "
<< fmap.size() << ")";
CHECK(fmt_ == "gl") << "Unknown OpenGL format " << fmt_;
program_ = workspace_->CreateProgram(data_.c_str());
Expand All @@ -83,7 +83,7 @@ OpenGLModuleNode::OpenGLModuleNode(
PackedFunc OpenGLModuleNode::GetFunction(
const std::string& name,
const std::shared_ptr<ModuleNode>& sptr_to_self) {
LOG_INFO.stream() << "OpenGLModuleNode::GetFunction(" << name << ")";
LOG(INFO) << "OpenGLModuleNode::GetFunction(" << name << ")";
CHECK_EQ(sptr_to_self.get(), this);
CHECK_NE(name, symbol::tvm_module_main) << "Device function do not have main";

Expand Down Expand Up @@ -123,19 +123,19 @@ OpenGLWrappedFunc::OpenGLWrappedFunc(
const std::vector<std::string>& thread_axis_tags)
: m_(m), sptr_(std::move(sptr)), func_name_(std::move(func_name)),
arg_size_(std::move(arg_size)) {
LOG_INFO.stream() << "OpenGLWrappedFunc(" << func_name_ << ", "
LOG(INFO) << "OpenGLWrappedFunc(" << func_name_ << ", "
<< "nargs = " << arg_size_.size() << ", "
<< "nthread_axis_tags = " << thread_axis_tags.size()
<< ")";
for (auto& a: arg_size_) { LOG_INFO.stream() << a; }
for (auto& t: thread_axis_tags) { LOG_INFO.stream() << t; }
for (auto& a: arg_size_) { LOG(INFO) << a; }
for (auto& t: thread_axis_tags) { LOG(INFO) << t; }

thread_axis_cfg_.Init(arg_size_.size(), thread_axis_tags);
}

void OpenGLWrappedFunc::operator()(TVMArgs args, TVMRetValue* rv,
void** void_args) const {
LOG_INFO.stream() << "OpenGLWrappedFunc::operator()";
LOG(INFO) << "OpenGLWrappedFunc::operator()";

// TODO(pengw): How to get variable names?
m_->workspace_->Render(
Expand All @@ -151,7 +151,7 @@ void OpenGLWrappedFunc::operator()(TVMArgs args, TVMRetValue* rv,
Module OpenGLModuleCreate(std::string data,
std::string fmt,
std::unordered_map<std::string, FunctionInfo> fmap) {
LOG_INFO.stream() << "OpenGLModuleCreate() " << data << " " << fmt << " "
LOG(INFO) << "OpenGLModuleCreate() " << data << " " << fmt << " "
<< fmap.size();
auto n = std::make_shared<OpenGLModuleNode>(data, fmt, fmap);
return Module(n);
Expand Down
1 change: 1 addition & 0 deletions src/schedule/schedule_lang.cc
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ Stage& Stage::opengl() {
CHECK(!all_iter_vars.empty()) << "At least one iter var";

// Fuse all dimensions to 1.
// TODO(zhixunt): Don't fuse reduction.
IterVar fused = all_iter_vars[0];
for (size_t i = 1; i != all_iter_vars.size(); ++i) {
fuse(fused, all_iter_vars[i], &fused);
Expand Down

0 comments on commit 26bba41

Please sign in to comment.