This source file includes following definitions.
- is_gpu_var
- is_gpu_block_var
- is_gpu_thread_var
- visit
- is_block_uniform
- visit
- visit
- buffer
- is_buffer_constant
#include "CodeGen_GPU_Dev.h"
#include "IRVisitor.h"
namespace Halide {
namespace Internal {
CodeGen_GPU_Dev::~CodeGen_GPU_Dev() {
}
bool CodeGen_GPU_Dev::is_gpu_var(const std::string &name) {
return is_gpu_block_var(name) || is_gpu_thread_var(name);
}
bool CodeGen_GPU_Dev::is_gpu_block_var(const std::string &name) {
return (ends_with(name, ".__block_id_x") ||
ends_with(name, ".__block_id_y") ||
ends_with(name, ".__block_id_z") ||
ends_with(name, ".__block_id_w"));
}
bool CodeGen_GPU_Dev::is_gpu_thread_var(const std::string &name) {
return (ends_with(name, ".__thread_id_x") ||
ends_with(name, ".__thread_id_y") ||
ends_with(name, ".__thread_id_z") ||
ends_with(name, ".__thread_id_w"));
}
namespace {
class IsBlockUniform : public IRVisitor {
using IRVisitor::visit;
void visit(const Variable *op) {
if (CodeGen_GPU_Dev::is_gpu_thread_var(op->name)) {
result = false;
}
}
public:
bool result;
IsBlockUniform() : result(true) {
}
};
}
bool CodeGen_GPU_Dev::is_block_uniform(Expr expr) {
IsBlockUniform v;
expr.accept(&v);
return v.result;
}
namespace {
class IsBufferConstant : public IRVisitor {
using IRVisitor::visit;
void visit(const Store *op) {
if (op->name == buffer) {
result = false;
}
if (result) {
IRVisitor::visit(op);
}
}
void visit(const Load *op) {
if (op->name == buffer &&
!CodeGen_GPU_Dev::is_block_uniform(op->index)) {
result = false;
}
if (result) {
IRVisitor::visit(op);
}
}
public:
bool result;
const std::string &buffer;
IsBufferConstant(const std::string &b) : result(true), buffer(b) {
}
};
}
bool CodeGen_GPU_Dev::is_buffer_constant(Stmt kernel,
const std::string &buffer) {
IsBufferConstant v(buffer);
kernel.accept(&v);
return v.result;
}
}}