opencl_kernel_configure.bzl 3.5 KB
Newer Older
1 2 3 4 5 6 7
"""Repository rule for opencl encrypt kernel autoconfiguration, borrow from tensorflow
"""
def _opencl_encrypt_kernel_impl(repository_ctx):
  repository_ctx.template(
      "BUILD",
      Label("//repository/opencl-kernel:BUILD.tpl"))

L
liuqi 已提交
8 9 10 11 12 13
  mace_root_path = str(repository_ctx.path(Label("@mace//:BUILD")))[:-len("BUILD")]

  ret = repository_ctx.execute(
      ["test", "-f", "%s/.git/logs/HEAD" % mace_root_path])
  if ret.return_code == 0:
    unused_var = repository_ctx.path(Label("//:.git/HEAD"))
L
liuqi 已提交
14 15 16
  ret = repository_ctx.execute(
      ["test", "-f", "%s/.git/refs/heads/master" % mace_root_path])
  if ret.return_code == 0:
L
liuqi 已提交
17 18
    unused_var = repository_ctx.path(Label("//:.git/refs/heads/master"))

L
liuqi 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
  ret = repository_ctx.execute(
      ["test", "-f", "%s/mace/kernels/opencl/cl/common.h" % mace_root_path])
  if ret.return_code == 0:
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/activation.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/addn.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/batch_norm.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/bias_add.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/buffer_to_image.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/channel_shuffle.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/common.h"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/concat.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/conv_2d.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/conv_2d_1x1.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/conv_2d_3x3.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/crop.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/deconv_2d.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/depth_to_space.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/depthwise_conv2d.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/eltwise.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/fully_connected.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/matmul.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/pad.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/pooling.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/reduce_mean.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/resize_bilinear.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/slice.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/softmax.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/space_to_batch.cl"))
    unused_var = repository_ctx.path(Label("//:mace/kernels/opencl/cl/winograd_transform.cl"))
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

  generated_files_path = repository_ctx.path("gen")

  python_bin_path = repository_ctx.which("python")

  repository_ctx.execute([
      python_bin_path, '%s/mace/python/tools/encrypt_opencl_codegen.py' % mace_root_path,
      '--cl_kernel_dir=%s/mace/kernels/opencl/cl' % mace_root_path,
      '--output_path=%s/encrypt_opencl_kernel' % generated_files_path
  ], quiet=False)


encrypt_opencl_kernel_repository = repository_rule(
    implementation = _opencl_encrypt_kernel_impl,
)