Skip to content

Commit

Permalink
use GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS instead of 1792 for portabi…
Browse files Browse the repository at this point in the history
…lity
  • Loading branch information
archibate committed Mar 27, 2020
1 parent 76ff830 commit 24bbc4a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions taichi/codegen/codegen_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ int _rand_i32()\n\

line_appender_header_.append_raw(kernel_header);

int threads_per_group = 1792;
if (num_threads_ < 1792)
int threads_per_group = opengl_get_threads_per_group();
if (num_threads_ < threads_per_group)
threads_per_group = num_threads_;
num_groups_ = (num_threads_ + 1791) / 1792;
num_groups_ = (num_threads_ + threads_per_group - 1) / threads_per_group;
if (threads_per_group == 0)
threads_per_group = 1;
emit("layout(local_size_x = {}, local_size_y = 1, local_size_z = 1) in;",
Expand Down
13 changes: 12 additions & 1 deletion taichi/platform/opengl/opengl_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ bool is_opengl_api_available() {
return true;
}

int opengl_get_threads_per_group() {
int ret = 1792;
glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, &ret);
return ret;
}

#else
void create_glsl_root_buffer(size_t size) {
TI_NOT_IMPLEMENTED
Expand All @@ -308,10 +314,15 @@ bool is_opengl_api_available() {
}

void initialize_opengl() {
TI_NOT_IMPLEMENTED
}

GLProgram *compile_glsl_program(std::string source) {
return nullptr;
TI_NOT_IMPLEMENTED
}

int opengl_get_threads_per_group() {
TI_NOT_IMPLEMENTED
}
#endif

Expand Down
1 change: 1 addition & 0 deletions taichi/platform/opengl/opengl_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void begin_glsl_kernels(const std::vector<IOV> &iov);
void launch_glsl_kernel(GLProgram *program, int num_groups);
void end_glsl_kernels(const std::vector<IOV> &iov);
GLProgram *compile_glsl_program(std::string source);
int opengl_get_threads_per_group();

} // namespace opengl

Expand Down

0 comments on commit 24bbc4a

Please sign in to comment.