635 lines
28 KiB
C++
635 lines
28 KiB
C++
/**
|
|
* Copyright 2019 Huawei Technologies Co., Ltd
|
|
*
|
|
* Licensed 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
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
// Include the header file "kernel/kernel_build_info.h" which contains information about the kernel build
|
|
#include "kernel/kernel_build_info.h"
|
|
|
|
// Include the algorithm header for using various algorithms like sorting, searching, etc.
|
|
#include <algorithm>
|
|
|
|
// Include the log_adapter.h file from the utils directory
|
|
#include "utils/log_adapter.h"
|
|
|
|
// Include the anf_dump_utils.h file from the common/debug directory
|
|
#include "include/common/debug/anf_dump_utils.h"
|
|
|
|
// Start of the "mindspore" namespace
|
|
namespace mindspore {
|
|
|
|
// Start of the "kernel" namespace
|
|
namespace kernel {
|
|
|
|
// Implementation of the GetInputFormat function of the KernelBuildInfo class
|
|
std::string KernelBuildInfo::GetInputFormat(size_t input_index) const {
|
|
|
|
// Check if the input index is valid
|
|
if (input_index >= inputs_format_.size()) {
|
|
|
|
// Log an error message indicating that the input index is out of bounds
|
|
MS_LOG(ERROR) << "The index [" << input_index << "] is exceed the number of input node";
|
|
|
|
// Return the constant string kInvalidFormat to indicate an invalid format
|
|
return kInvalidFormat;
|
|
}
|
|
|
|
// Return the input format at the specified index
|
|
return inputs_format_[input_index];
|
|
}
|
|
|
|
} // End of the "kernel" namespace
|
|
|
|
} // End of the "mindspore" namespace
|
|
|
|
// Function to get the output format for a given output index
|
|
std::string KernelBuildInfo::GetOutputFormat(size_t output_index) const {
|
|
|
|
// Check if the output index is within the range of available output formats
|
|
if (output_index >= outputs_format_.size()) {
|
|
|
|
// If the output index is out of range, log an error message with the index and return an invalid format
|
|
MS_LOG(ERROR) << "The index [" << output_index << "] is exceed the number of output";
|
|
return kInvalidFormat;
|
|
}
|
|
|
|
// If the output index is valid, return the corresponding output format
|
|
return outputs_format_[output_index];
|
|
}
|
|
|
|
// Get the input device type for a given input index in the KernelBuildInfo class
|
|
TypeId KernelBuildInfo::GetInputDeviceType(size_t input_index) const {
|
|
|
|
// Check if the input index is greater than or equal to the size of the inputs_device_type_ vector
|
|
if (input_index >= inputs_device_type_.size()) {
|
|
|
|
// If the input index is out of range, log an error message with the index value
|
|
MS_LOG(ERROR) << "The index [" << input_index << "] is exceed the number of input";
|
|
|
|
// Return TypeId::kNumberTypeEnd to indicate an error condition
|
|
return TypeId::kNumberTypeEnd;
|
|
}
|
|
|
|
// If the input index is within range, return the input device type at the specified index
|
|
return inputs_device_type_[input_index];
|
|
}
|
|
|
|
// Get the output device type for a given output index in the KernelBuildInfo object
|
|
TypeId KernelBuildInfo::GetOutputDeviceType(size_t output_index) const {
|
|
|
|
// Check if the output index is valid (within the range of outputs_device_type_)
|
|
if (output_index >= outputs_device_type_.size()) {
|
|
|
|
// If the output index is invalid, log an error message with the index and return TypeId::kNumberTypeEnd
|
|
MS_LOG(ERROR) << "The index [" << output_index << "] is exceed the number of output";
|
|
return TypeId::kNumberTypeEnd;
|
|
}
|
|
|
|
// If the output index is valid, return the output device type at the specified index
|
|
return outputs_device_type_[output_index];
|
|
}
|
|
|
|
// Define a member function named GetOriginDataFormat() of the class KernelBuildInfo
|
|
// The function returns a constant reference to a std::string object
|
|
const std::string &KernelBuildInfo::GetOriginDataFormat() const {
|
|
// Return the value of the member variable origin_data_format_
|
|
return origin_data_format_;
|
|
}
|
|
|
|
// Define a member function named GetAllInputFormats() of the class KernelBuildInfo
|
|
// This function returns a constant reference to a vector of strings
|
|
|
|
const std::vector<std::string> &KernelBuildInfo::GetAllInputFormats() const {
|
|
// Return the private member variable inputs_format_
|
|
return inputs_format_;
|
|
}
|
|
|
|
// Define a member function named GetAllOutputFormats() of the class KernelBuildInfo
|
|
// This function returns a constant reference to a vector of strings
|
|
|
|
const std::vector<std::string> &KernelBuildInfo::GetAllOutputFormats() const {
|
|
// Return the private member variable outputs_format_
|
|
return outputs_format_;
|
|
}
|
|
|
|
// Define a member function named GetAllInputDeviceTypes() of the class KernelBuildInfo
|
|
// The function returns a constant reference to a vector of TypeId objects
|
|
const std::vector<TypeId> &KernelBuildInfo::GetAllInputDeviceTypes() const {
|
|
// Return the private member variable inputs_device_type_
|
|
return inputs_device_type_;
|
|
}
|
|
|
|
// Define a member function named GetAllOutputDeviceTypes in the class KernelBuildInfo
|
|
// This function returns a constant reference to a vector of TypeId objects
|
|
const std::vector<TypeId> &KernelBuildInfo::GetAllOutputDeviceTypes() const {
|
|
// Return the private member variable outputs_device_type_
|
|
return outputs_device_type_;
|
|
}
|
|
|
|
// A member function of the class KernelBuildInfo that sets the output format for a given index
|
|
void KernelBuildInfo::SetOutputFormat(const std::string &format, size_t index) {
|
|
|
|
// Check if the given index is within the range of the outputs_format_ vector
|
|
if (index >= outputs_format_.size()) {
|
|
|
|
// If the index is out of range, throw an exception with an error message
|
|
MS_LOG(EXCEPTION) << "The index [" << index << "] is exceed the number of output";
|
|
}
|
|
|
|
// Set the output format at the given index to the provided format
|
|
outputs_format_[index] = format;
|
|
}
|
|
|
|
// Define the function "SetOutputsFormat" belonging to the class "KernelBuildInfo"
|
|
void KernelBuildInfo::SetOutputsFormat(const std::vector<std::string> &outputs_format) {
|
|
|
|
// Assign the input vector "outputs_format" to the member variable "outputs_format_" of the class
|
|
outputs_format_ = outputs_format;
|
|
}
|
|
|
|
// A member function of the KernelBuildInfo class that sets the output device type for a given index
|
|
void KernelBuildInfo::SetOutputDeviceType(const TypeId &output_device_type, size_t index) {
|
|
|
|
// Check if the index is within the bounds of the outputs_device_type_ vector
|
|
if (index >= outputs_device_type_.size()) {
|
|
|
|
// If the index is out of bounds, throw an exception with an error message
|
|
MS_LOG(EXCEPTION) << "The index [" << index << "] is exceed the number of output";
|
|
}
|
|
|
|
// Set the output device type at the specified index to the provided output_device_type
|
|
outputs_device_type_[index] = output_device_type;
|
|
}
|
|
|
|
// Define the function "SetOutputsDeviceType" belonging to the class "KernelBuildInfo"
|
|
void KernelBuildInfo::SetOutputsDeviceType(const std::vector<TypeId> &outputs_device_type) {
|
|
|
|
// Assign the input vector "outputs_device_type" to the member variable "outputs_device_type_"
|
|
outputs_device_type_ = outputs_device_type;
|
|
}
|
|
|
|
// Define the member function GetInputNum() of the class KernelBuildInfo
|
|
// It returns the number of inputs in the inputs_format_ vector
|
|
size_t KernelBuildInfo::GetInputNum() const {
|
|
// Return the size of the inputs_format_ vector
|
|
return inputs_format_.size();
|
|
}
|
|
|
|
// Define a member function named "GetOutputNum" of the class "KernelBuildInfo"
|
|
// The function returns a value of type "size_t"
|
|
size_t KernelBuildInfo::GetOutputNum() const {
|
|
|
|
// Return the size of the "outputs_format_" vector
|
|
return outputs_format_.size();
|
|
}
|
|
|
|
// Define a member function named GetOutputNumWithoutMonad in the KernelBuildInfo class that returns a size_t value
|
|
size_t KernelBuildInfo::GetOutputNumWithoutMonad() const {
|
|
|
|
// Use the std::count_if algorithm to count the number of elements in the outputs_device_type_ container
|
|
// that do not have the value TypeId::kObjectTypeUMonad
|
|
const auto count = std::count_if(outputs_device_type_.begin(), outputs_device_type_.end(),
|
|
[](TypeId type) { return type != TypeId::kObjectTypeUMonad; });
|
|
|
|
// Convert the count to size_t and return it
|
|
return static_cast<size_t>(count);
|
|
}
|
|
|
|
// This function is a member function of the class KernelBuildInfo and returns a string.
|
|
// It takes a size_t input_index as a parameter.
|
|
|
|
std::string KernelBuildInfo::GetInputReshapeType(size_t input_index) const {
|
|
|
|
// Check if the input_reshape_type_ vector is empty.
|
|
if (input_reshape_type_.empty()) {
|
|
return "";
|
|
}
|
|
|
|
// Check if the input_index is greater than or equal to the size of the input_reshape_type_ vector.
|
|
if (input_index >= input_reshape_type_.size()) {
|
|
|
|
// If the condition is true, throw an exception with a log message indicating the index is out of bounds.
|
|
MS_LOG(EXCEPTION) << "The index [" << input_index << "] is exceed the number of input node size "
|
|
<< input_reshape_type_.size();
|
|
}
|
|
|
|
// Return the element at the specified index in the input_reshape_type_ vector.
|
|
return input_reshape_type_[input_index];
|
|
}
|
|
|
|
// This function is a member function of the class KernelBuildInfo and returns a string.
|
|
// It takes a size_t input_index as a parameter.
|
|
|
|
std::string KernelBuildInfo::GetInputValueDepend(size_t input_index) const {
|
|
|
|
// Check if the input_value_depend_ vector is empty.
|
|
if (input_value_depend_.empty()) {
|
|
return "";
|
|
}
|
|
|
|
// Check if the input_index is greater than or equal to the size of the input_value_depend_ vector.
|
|
if (input_index >= input_value_depend_.size()) {
|
|
|
|
// If the input_index is greater than the size of the vector, throw an exception with a descriptive error message.
|
|
MS_LOG(EXCEPTION) << "The index [" << input_index << "] is exceed the number of input node size "
|
|
<< input_value_depend_.size();
|
|
}
|
|
|
|
// Return the value at the input_index position in the input_value_depend_ vector.
|
|
return input_value_depend_[input_index];
|
|
}
|
|
|
|
// Function to get the output reshape type for a given output index
|
|
std::string KernelBuildInfo::GetOutputReshapeType(size_t output_index) const {
|
|
|
|
// Check if the output reshape type vector is empty
|
|
if (output_reshape_type_.empty()) {
|
|
return "";
|
|
}
|
|
|
|
// Check if the output index is within the bounds of the output reshape type vector
|
|
if (output_index >= output_reshape_type_.size()) {
|
|
|
|
// Throw an exception with an error message indicating the index is out of bounds
|
|
MS_LOG(EXCEPTION) << "The index [" << output_index << "] is exceed the number of output node size "
|
|
<< output_reshape_type_.size();
|
|
}
|
|
|
|
// Return the output reshape type at the given output index
|
|
return output_reshape_type_[output_index];
|
|
}
|
|
|
|
// Define the ToString() function of the KernelBuildInfo class
|
|
std::string KernelBuildInfo::ToString() const {
|
|
|
|
// Create an output buffer using ostringstream to store the string representation of the KernelBuildInfo object
|
|
std::ostringstream output_buffer;
|
|
|
|
// Append "(" to the output buffer
|
|
output_buffer << "(";
|
|
|
|
// Iterate over the input devices
|
|
for (size_t index = 0; index < GetInputNum(); ++index) {
|
|
|
|
// If it's not the first input device, append a comma and a space to the output buffer
|
|
if (index != 0) {
|
|
output_buffer << ", ";
|
|
}
|
|
|
|
// Append the short string representation of the input device type, followed by "x" and the input format to the output buffer
|
|
output_buffer << "<" << TypeToShortString(GetInputDeviceType(index)) << "x" << GetInputFormat(index) << ">";
|
|
}
|
|
|
|
// Append ") -> (" to the output buffer
|
|
output_buffer << ") -> (";
|
|
|
|
// Iterate over the output devices
|
|
for (size_t index = 0; index < GetOutputNum(); ++index) {
|
|
|
|
// If it's not the first output device, append a comma and a space to the output buffer
|
|
if (index != 0) {
|
|
output_buffer << ", ";
|
|
}
|
|
|
|
// Append the short string representation of the output device type, followed by "x" and the output format to the output buffer
|
|
output_buffer << "<" << TypeToShortString(GetOutputDeviceType(index)) << "x" << GetOutputFormat(index) << ">";
|
|
}
|
|
|
|
// Append ")" to the output buffer
|
|
output_buffer << ")";
|
|
|
|
// Return the string representation of the output buffer
|
|
return output_buffer.str();
|
|
}
|
|
|
|
// Check if the inputs and outputs formats of the current KernelBuildInfo object are different from the other KernelBuildInfo object
|
|
bool KernelBuildInfo::IsSimilarityKernelBuildInfo(const KernelBuildInfo &other) const {
|
|
|
|
// If the inputs format or outputs format are different
|
|
if (inputs_format_ != other.inputs_format_ || outputs_format_ != other.outputs_format_) {
|
|
|
|
// If the operation pattern is not format agnostic
|
|
if (op_pattern_ != kFormatAgnosticPattern) {
|
|
|
|
// Return false to indicate that the kernel build info is not similar
|
|
return false;
|
|
} else {
|
|
|
|
// Print an informational message indicating the difference in kernel build info
|
|
MS_LOG(INFO) << "This kernel build info:" << this->ToString()
|
|
<< ", other kernel build info: " << other.ToString();
|
|
}
|
|
}
|
|
|
|
// Check if the inputs device type or outputs device type are different
|
|
return !(inputs_device_type_ != other.inputs_device_type_ || outputs_device_type_ != other.outputs_device_type_);
|
|
}
|
|
|
|
// Define the equality comparison operator for the KernelBuildInfo class
|
|
bool KernelBuildInfo::operator==(const KernelBuildInfo &other) const {
|
|
|
|
// Check if the kernel_type_, fusion_type_, and processor_ of the current object are not equal to the corresponding values of the other object
|
|
if (kernel_type_ != other.kernel_type_ || fusion_type_ != other.fusion_type_ || processor_ != other.processor_) {
|
|
return false;
|
|
}
|
|
|
|
// If the above condition is not met, call the IsSimilarityKernelBuildInfo function to check for similarity between the two objects
|
|
return IsSimilarityKernelBuildInfo(other);
|
|
}
|
|
|
|
// This function is a member function of the KernelBuildInfo class
|
|
// It checks if the input reshape type is empty and returns a boolean value
|
|
|
|
bool KernelBuildInfo::IsInputDefaultPadding() const {
|
|
// Check if the input reshape type is empty
|
|
return input_reshape_type_.empty();
|
|
}
|
|
|
|
// This function is a member function of the KernelBuildInfo class
|
|
// It checks if the output reshape type is empty and returns a boolean value
|
|
|
|
bool KernelBuildInfo::IsOutputDefaultPadding() const {
|
|
// Check if the output reshape type is empty
|
|
return output_reshape_type_.empty();
|
|
}
|
|
|
|
// Define the inequality operator for the KernelBuildInfo class
|
|
bool KernelBuildInfo::operator!=(const KernelBuildInfo &other) const {
|
|
|
|
// Use the equality operator to compare the current object with the other object
|
|
// and negate the result to get the inequality
|
|
return !((*this) == other);
|
|
}
|
|
|
|
// Define the function "SetKernelType" in the namespace "KernelBuildInfo::KernelBuildInfoBuilder"
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetKernelType(const KernelType &kernel_type) {
|
|
|
|
// Check if the pointer "kernel_build_info_" is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the "kernel_type_" member variable of the "kernel_build_info_" object to the provided "kernel_type"
|
|
kernel_build_info_->kernel_type_ = kernel_type;
|
|
}
|
|
|
|
// Define the function `SetOriginDataFormat` which takes a constant reference to a string as input
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetOriginDataFormat(const std::string &origin_data_format) {
|
|
|
|
// Check if the pointer `kernel_build_info_` is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the `origin_data_format_` member variable of `kernel_build_info_` to the provided `origin_data_format`
|
|
kernel_build_info_->origin_data_format_ = origin_data_format;
|
|
}
|
|
|
|
// Define the function `SetInputsFormat` which takes a reference to a vector of strings as input
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetInputsFormat(const std::vector<std::string> &inputs_format) {
|
|
|
|
// Check if the `kernel_build_info_` pointer is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the `inputs_format_` member variable of the `kernel_build_info_` object to the provided `inputs_format`
|
|
kernel_build_info_->inputs_format_ = inputs_format;
|
|
}
|
|
|
|
// Define the function `SetOutputsFormat` which takes a reference to a vector of strings as input
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetOutputsFormat(const std::vector<std::string> &outputs_format) {
|
|
|
|
// Check if the pointer `kernel_build_info_` is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the `outputs_format_` member variable of `kernel_build_info_` to the provided `outputs_format`
|
|
kernel_build_info_->outputs_format_ = outputs_format;
|
|
}
|
|
|
|
// Define the function `SetInputsDeviceType` belonging to the `KernelBuildInfoBuilder` class within the `KernelBuildInfo` namespace
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetInputsDeviceType(const std::vector<TypeId> &inputs_device_type) {
|
|
|
|
// Check if the `kernel_build_info_` pointer is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the `inputs_device_type_` member variable of the `kernel_build_info_` object to the provided `inputs_device_type` vector
|
|
kernel_build_info_->inputs_device_type_ = inputs_device_type;
|
|
}
|
|
|
|
// Define the function `SetOutputsDeviceType` which takes a reference to a vector of TypeId objects as input
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetOutputsDeviceType(const std::vector<TypeId> &outputs_device_type) {
|
|
|
|
// Check if the pointer `kernel_build_info_` is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the `outputs_device_type_` member variable of the `kernel_build_info_` object to the provided vector
|
|
kernel_build_info_->outputs_device_type_ = outputs_device_type;
|
|
}
|
|
|
|
// Define the function SetFusionType which takes a FusionType parameter
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetFusionType(FusionType fusion_type) {
|
|
|
|
// Check if the kernel_build_info_ pointer is null, throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the fusion_type_ member variable of the kernel_build_info_ object to the provided fusion_type
|
|
kernel_build_info_->fusion_type_ = fusion_type;
|
|
}
|
|
|
|
// Define the function `SetCoreType` which takes a constant reference to a string as input
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetCoreType(const std::string &core_type) {
|
|
|
|
// Check if the pointer `kernel_build_info_` is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the `core_type_` member variable of the `kernel_build_info_` object to the provided `core_type`
|
|
kernel_build_info_->core_type_ = core_type;
|
|
}
|
|
|
|
// Define the function `SetOutputDataDesc` which belongs to the `KernelBuildInfoBuilder` class within the `KernelBuildInfo` namespace
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetOutputDataDesc(const std::vector<nlohmann::json> &data_desc) {
|
|
|
|
// Check if the `kernel_build_info_` pointer is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the `output_data_desc_` member variable of the `kernel_build_info_` object to the provided `data_desc` vector
|
|
kernel_build_info_->output_data_desc_ = data_desc;
|
|
}
|
|
|
|
// Define the function SetProcessor in the KernelBuildInfoBuilder class
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetProcessor(Processor processor) {
|
|
|
|
// Check if the kernel_build_info_ pointer is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the processor of the kernel_build_info_ object to the provided processor
|
|
kernel_build_info_->processor_ = processor;
|
|
}
|
|
|
|
// Define the member function `Build()` of the `KernelBuildInfoBuilder` class, which returns a `shared_ptr` to a `KernelBuildInfo` object
|
|
std::shared_ptr<KernelBuildInfo> KernelBuildInfo::KernelBuildInfoBuilder::Build() {
|
|
// Return the `kernel_build_info_` object
|
|
return kernel_build_info_;
|
|
}
|
|
|
|
// Define the function `SetInputsReshapeType` which takes a reference to a vector of strings as input
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetInputsReshapeType(const std::vector<std::string> &input_reshape_type) {
|
|
|
|
// Check if the `kernel_build_info_` pointer is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the `input_reshape_type_` member variable of the `kernel_build_info_` object to the provided input vector
|
|
kernel_build_info_->input_reshape_type_ = input_reshape_type;
|
|
}
|
|
|
|
// Define the function `SetInputsValueDepend` belonging to the `KernelBuildInfoBuilder` class within the `KernelBuildInfo` namespace
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetInputsValueDepend(const std::vector<std::string> &input_value_depend) {
|
|
|
|
// Check if the `kernel_build_info_` pointer is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the `input_value_depend_` member variable of the `kernel_build_info_` object to the provided `input_value_depend` vector
|
|
kernel_build_info_->input_value_depend_ = input_value_depend;
|
|
}
|
|
|
|
// Define the function `SetOutputsReshapeType` belonging to the `KernelBuildInfoBuilder` class within the `KernelBuildInfo` namespace
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetOutputsReshapeType(const std::vector<std::string> &output_reshape_type) {
|
|
|
|
// Check if the `kernel_build_info_` pointer is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the `output_reshape_type_` member variable of the `kernel_build_info_` object to the provided `output_reshape_type` vector
|
|
kernel_build_info_->output_reshape_type_ = output_reshape_type;
|
|
}
|
|
|
|
// Set the operation pattern of the kernel build info
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetOpPattern(OpPattern pattern) {
|
|
// Check if the kernel build info is null
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Set the operation pattern of the kernel build info
|
|
kernel_build_info_->op_pattern_ = pattern;
|
|
}
|
|
|
|
// Set the input format of the kernel build info for a specific index
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetInputFormat(const std::string &format, size_t index) {
|
|
// Check if the kernel build info is null
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Get the limit of the input formats
|
|
auto index_limit = kernel_build_info_->inputs_format_.size();
|
|
|
|
// Check if the index is out of range
|
|
if (index >= index_limit) {
|
|
MS_LOG(EXCEPTION) << "Index of input format out of range! The value should be less than: " << index_limit
|
|
<< ", but got: " << index;
|
|
}
|
|
|
|
// Set the input format at the specified index
|
|
kernel_build_info_->inputs_format_[index] = format;
|
|
}
|
|
|
|
// Define the function SetOutputFormat in the KernelBuildInfo::KernelBuildInfoBuilder class
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetOutputFormat(const std::string &format, size_t index) {
|
|
// Check if the kernel_build_info_ pointer is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Get the size of the outputs_format_ vector in kernel_build_info_
|
|
auto index_limit = kernel_build_info_->outputs_format_.size();
|
|
|
|
// Check if the index is out of range, and throw an exception if it is
|
|
if (index >= index_limit) {
|
|
MS_LOG(EXCEPTION) << "Index of output format out of range! The value should be less than: " << index_limit
|
|
<< ", but got: " << index;
|
|
}
|
|
|
|
// Set the output format at the specified index in the outputs_format_ vector to the given format
|
|
kernel_build_info_->outputs_format_[index] = format;
|
|
}
|
|
|
|
// Define the function SetInputReshapeType in the KernelBuildInfo::KernelBuildInfoBuilder class
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetInputReshapeType(const std::string &input_reshape_type, size_t index) {
|
|
// Check if the kernel_build_info_ pointer is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Get the size of the input_reshape_type_ vector in kernel_build_info_
|
|
auto index_limit = kernel_build_info_->input_reshape_type_.size();
|
|
|
|
// Check if the index is out of range, and throw an exception if it is
|
|
if (index >= index_limit) {
|
|
MS_LOG(EXCEPTION) << "Index of input_reshape_type out of range! The value should be less than: " << index_limit
|
|
<< ", but got: " << index;
|
|
}
|
|
|
|
// Copy the characters from input_reshape_type to the input_reshape_type_ vector at the specified index
|
|
(void)std::copy(input_reshape_type.begin(), input_reshape_type.end(),
|
|
std::back_inserter(kernel_build_info_->input_reshape_type_[index]));
|
|
}
|
|
|
|
// Define the function `SetOutputReshapeType` in the `KernelBuildInfoBuilder` class of the `KernelBuildInfo` namespace
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetOutputReshapeType(const std::string &output_reshape_type,
|
|
size_t index) {
|
|
// Check if the `kernel_build_info_` pointer is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Get the size of the `output_reshape_type_` vector in the `kernel_build_info_` object
|
|
auto index_limit = kernel_build_info_->output_reshape_type_.size();
|
|
|
|
// Check if the given `index` is out of range, and throw an exception if it is
|
|
if (index >= index_limit) {
|
|
MS_LOG(EXCEPTION) << "Index of output_reshape_type out of range! The value should be less than: " << index_limit
|
|
<< ", but got: " << index;
|
|
}
|
|
|
|
// Copy the characters from the `output_reshape_type` string to the `output_reshape_type_` vector at the given `index`
|
|
(void)std::copy(output_reshape_type.begin(), output_reshape_type.end(),
|
|
std::back_inserter(kernel_build_info_->output_reshape_type_[index]));
|
|
}
|
|
|
|
// Define the function `SetOutputDeviceType` in the `KernelBuildInfoBuilder` class of the `KernelBuildInfo` namespace
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetOutputDeviceType(const TypeId &output_device_type, size_t index) {
|
|
// Check if the `kernel_build_info_` pointer is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Get the size of the `outputs_device_type_` vector from the `kernel_build_info_` object
|
|
auto index_limit = kernel_build_info_->outputs_device_type_.size();
|
|
|
|
// Check if the given `index` is out of range, and throw an exception if it is
|
|
if (index >= index_limit) {
|
|
MS_LOG(EXCEPTION) << "Index of output_device_type out of range! The value should be less than: " << index_limit
|
|
<< ", but got: " << index;
|
|
}
|
|
|
|
// Set the `output_device_type` at the given `index` in the `outputs_device_type_` vector of the `kernel_build_info_` object
|
|
kernel_build_info_->outputs_device_type_[index] = output_device_type;
|
|
}
|
|
|
|
// Define the function `SetInputDeviceType` in the `KernelBuildInfoBuilder` class of the `KernelBuildInfo` namespace
|
|
void KernelBuildInfo::KernelBuildInfoBuilder::SetInputDeviceType(const TypeId &input_device_type, size_t index) {
|
|
// Check if the `kernel_build_info_` pointer is null, and throw an exception if it is
|
|
MS_EXCEPTION_IF_NULL(kernel_build_info_);
|
|
|
|
// Get the size of the `inputs_device_type_` vector from the `kernel_build_info_` object
|
|
auto index_limit = kernel_build_info_->inputs_device_type_.size();
|
|
|
|
// Check if the given `index` is out of range, and throw an exception if it is
|
|
if (index >= index_limit) {
|
|
MS_LOG(EXCEPTION) << "Index of input_device_type out of range! The value should be less than: " << index_limit
|
|
<< ", but got: " << index;
|
|
}
|
|
|
|
// Set the `input_device_type` at the given `index` in the `inputs_device_type_` vector of the `kernel_build_info_` object
|
|
kernel_build_info_->inputs_device_type_[index] = input_device_type;
|
|
}
|
|
|
|
// End of the `kernel` namespace
|
|
} // namespace kernel
|
|
|
|
// End of the `mindspore` namespace
|
|
} // namespace mindspore
|