codegen_opengl.h 2.37 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12 13 14 15 16 17 18 19
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

20 21 22 23
/*!
 * \file codegen_opengl.h
 * \brief Generate OpenGL device code.
 */
24 25
#ifndef TVM_TARGET_SOURCE_CODEGEN_OPENGL_H_
#define TVM_TARGET_SOURCE_CODEGEN_OPENGL_H_
26

27
#include <tvm/target/codegen.h>
28
#include <string>
29 30
#include <unordered_set>
#include <unordered_map>
31
#include "codegen_c.h"
32
#include "../../runtime/opengl/opengl_module.h"
33 34 35 36 37 38 39 40 41 42 43 44

namespace tvm {
namespace codegen {

class CodeGenOpenGL final : public CodeGenC {
 public:
  CodeGenOpenGL();
  void AddFunction(LoweredFunc f);
  std::unordered_map<std::string, runtime::OpenGLShader> Finish();

  void InitFuncState(LoweredFunc f) final;
  void BindThreadIndex(const IterVar& iv) final;
45
  void VisitStmt_(const StoreNode* op) final;
46 47
  std::string TexelFetch(const VarNode* buffer, PrimExpr index);
  std::string GetBufferRef(DataType t, const VarNode* buffer, PrimExpr index) final;
48
  void PrintType(DataType t, std::ostream& os) final; // NOLINT(*)
49 50

  // Codegen for immediate values
51 52 53
  void VisitExpr_(const IntImmNode* op, std::ostream& os) final;  // NOLINT(*)
  void VisitExpr_(const FloatImmNode* op, std::ostream& os) final;  // NOLINT(*)
  void VisitExpr_(const StringImmNode* op, std::ostream& os) final;  // NOLINT(*)
54

55
  // Match glsl_texture_store Call.
56
  void VisitStmt_(const EvaluateNode* op) final;  // NOLINT(*)
57

58
 private:
59 60 61
  const VarNode* output_{nullptr};
  std::unordered_set<const VarNode*> inputs_;
  const VarNode* output_iter_var_{nullptr};
62 63 64 65 66 67 68
  std::unordered_map<std::string, runtime::OpenGLShader> shaders_;
  std::string thread_extent_var_;
};

}  // namespace codegen
}  // namespace tvm

69
#endif  // TVM_TARGET_SOURCE_CODEGEN_OPENGL_H_