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.

custom.cc 1.9 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Copyright 2021 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "ops/custom.h"
  17. #include <memory>
  18. #include <map>
  19. namespace mindspore {
  20. namespace ops {
  21. void Custom::Init(const std::string &type, const std::map<std::string, std::vector<uint8_t>> &attrs) {
  22. this->set_type(type);
  23. this->set_attr(attrs);
  24. }
  25. void Custom::set_type(const std::string &type) { this->AddAttr(kType, MakeValue(type)); }
  26. std::string Custom::get_type() const {
  27. auto value_ptr = this->GetAttr(kType);
  28. return GetValue<std::string>(value_ptr);
  29. }
  30. void Custom::set_attr(const std::map<std::string, std::vector<uint8_t>> &attrs) {
  31. ValuePtrList value_ptr_list;
  32. for (const auto &attr : attrs) {
  33. value_ptr_list.emplace_back(MakeValue<std::string>(attr.first));
  34. value_ptr_list.emplace_back(MakeValue<std::vector<uint8_t>>(attr.second));
  35. }
  36. this->AddAttr(kAttr, MakeValue(value_ptr_list));
  37. }
  38. std::map<std::string, std::vector<uint8_t>> Custom::get_attr() const {
  39. std::map<std::string, std::vector<uint8_t>> attrs;
  40. auto value_ptr_list = GetValue<ValuePtrList>(this->GetAttr(kAttr));
  41. for (size_t i = 0; i < value_ptr_list.size(); i += 2) {
  42. auto key = GetValue<std::string>(value_ptr_list[i]);
  43. auto value = GetValue<std::vector<uint8_t>>(value_ptr_list[i + 1]);
  44. attrs[key] = value;
  45. }
  46. return attrs;
  47. }
  48. REGISTER_PRIMITIVE_C(kNameCustom, Custom);
  49. } // namespace ops
  50. } // namespace mindspore