1 #ifndef HALIDE_CODEGEN_OPENGLCOMPUTE_DEV_H 2 #define HALIDE_CODEGEN_OPENGLCOMPUTE_DEV_H 3 4 /** \file 5 * Defines the code-generator for producing GLSL kernel code for OpenGL Compute. 6 */ 7 8 #include <map> 9 #include <sstream> 10 11 #include "CodeGen_C.h" 12 #include "CodeGen_GPU_Dev.h" 13 #include "CodeGen_OpenGL_Dev.h" 14 #include "Target.h" 15 16 namespace Halide { 17 namespace Internal { 18 19 class CodeGen_OpenGLCompute_Dev : public CodeGen_GPU_Dev { 20 public: 21 CodeGen_OpenGLCompute_Dev(Target target); 22 23 // CodeGen_GPU_Dev interface 24 void add_kernel(Stmt stmt, 25 const std::string &name, 26 const std::vector<DeviceArgument> &args) override; 27 28 void init_module() override; 29 30 std::vector<char> compile_to_src() override; 31 32 std::string get_current_kernel_name() override; 33 34 void dump() override; 35 36 std::string print_gpu_name(const std::string &name) override; 37 api_unique_name()38 std::string api_unique_name() override { 39 return "openglcompute"; 40 } kernel_run_takes_types()41 bool kernel_run_takes_types() const override { 42 return true; 43 } 44 45 protected: 46 class CodeGen_OpenGLCompute_C : public CodeGen_GLSLBase { 47 public: 48 CodeGen_OpenGLCompute_C(std::ostream &s, Target t); 49 void add_kernel(const Stmt &stmt, 50 const std::string &name, 51 const std::vector<DeviceArgument> &args); 52 53 protected: 54 std::string print_type(Type type, AppendSpaceIfNeeded space_option = DoNotAppendSpace) override; 55 56 using CodeGen_GLSLBase::visit; 57 void visit(const For *) override; 58 void visit(const Ramp *op) override; 59 void visit(const Broadcast *op) override; 60 void visit(const Load *op) override; 61 void visit(const Store *op) override; 62 void visit(const Call *op) override; 63 void visit(const Allocate *op) override; 64 void visit(const Free *op) override; 65 void visit(const Select *op) override; 66 void visit(const Evaluate *op) override; 67 void visit(const IntImm *op) override; 68 69 public: 70 int workgroup_size[3]; 71 }; 72 73 std::ostringstream src_stream; 74 std::string cur_kernel_name; 75 CodeGen_OpenGLCompute_C glc; 76 }; 77 78 } // namespace Internal 79 } // namespace Halide 80 81 #endif 82