build_opencl.cc 992 Bytes
Newer Older
1 2 3 4 5 6 7 8
/*!
 *  Copyright (c) 2017 by Contributors
 *  Build opencl modules from source.
 * \file build_opencl.cc
 */
#include <tvm/base.h>
#include <tvm/runtime/config.h>
#include "./codegen_opencl.h"
9
#include "./build_common.h"
10 11 12

#if TVM_OPENCL_RUNTIME
#include "../runtime/opencl/opencl_module.h"
13
#endif   // TVM_OPENCL_RUNTIME
14 15 16 17 18 19 20 21 22 23 24 25

namespace tvm {
namespace codegen {

runtime::Module BuildOpenCL(Array<LoweredFunc> funcs) {
  bool output_ssa = false;
  CodeGenOpenCL cg;
  cg.Init(output_ssa);
  for (LoweredFunc f : funcs) {
    cg.AddFunction(f);
  }
  std::string code = cg.Finish();
26 27 28 29 30 31
#if TVM_OPENCL_RUNTIME
  return OpenCLModuleCreate(code, "cl", ExtractFuncInfo(funcs));
#else
  LOG(WARNING) << "OpenCL runtime not enabled, return a source module...";
  return SourceModuleCreate(code, "cl");
#endif   // TVM_OPENCL_RUNTIME
32 33
}

34
TVM_REGISTER_API("codegen.build_opencl")
35 36 37 38 39
.set_body([](TVMArgs args, TVMRetValue* rv) {
    *rv = BuildOpenCL(args[0]);
  });
}  // namespace codegen
}  // namespace tvm