You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

assign.py 2.3 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """operator dsl function:Assign"""
  15. import akg
  16. import akg.topi as topi
  17. import akg.tvm
  18. from akg.utils import validation_check as vc_util
  19. from akg.utils import kernel_exec as utils
  20. @akg.schedule(topi.cuda.injective_single_kernel.schedule_injective)
  21. def Assign(ref, val):
  22. """
  23. Assign val to ref.
  24. Args:
  25. ref: Tensor, which is mutable.
  26. val: Tensor, which will be assigned to ref.
  27. Returns:
  28. fake_output: Tensor, all zeros has the same shape as ref, needed by ME.
  29. ref_val: Tensor, ref assigned with val.
  30. attrs: Dictionary, indicates that ref and ref_val share the same buf.
  31. """
  32. dtype = val.dtype
  33. vc_util.ops_dtype_check(dtype, [vc_util.DtypeForDavinci.ALL_FLOAT, vc_util.DtypeForDavinci.INT8,
  34. vc_util.DtypeForDavinci.INT16, vc_util.DtypeForDavinci.INT32,
  35. vc_util.DtypeForDavinci.INT64, vc_util.DtypeForDavinci.UINT8,
  36. vc_util.DtypeForDavinci.UINT16, vc_util.DtypeForDavinci.UINT32,
  37. vc_util.DtypeForDavinci.UINT64])
  38. shape1 = [x.value for x in ref.shape]
  39. shape2 = [x.value for x in val.shape]
  40. if shape1 != shape2:
  41. raise RuntimeError("assign operations need input shape equal!")
  42. vc_util.check_shape(shape2)
  43. ref_val = akg.tvm.compute(shape2, lambda *indice: val(*indice), name="ref_val")
  44. ref_val, binds_info = utils.TensorUtils.inplace_set(ref, ref_val)
  45. attrs = {utils.BINDS: binds_info}
  46. fake_output = akg.tvm.compute(ref.shape, lambda *indice: ref_val(*indice), name="fake_output")
  47. return fake_output, ref_val, attrs