Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cmake/onnxruntime_providers_vitisai.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@
"${ONNXRUNTIME_ROOT}/core/providers/shared_library/*.cc"
)
source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_providers_vitisai_cc_srcs})
onnxruntime_add_shared_library(onnxruntime_providers_vitisai ${onnxruntime_providers_vitisai_cc_srcs})
set(onnxruntime_providers_vitisai_all_srcs ${onnxruntime_providers_vitisai_cc_srcs})
if(WIN32)
# Sets the DLL version info on Windows: https://learn.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource
list(APPEND onnxruntime_providers_vitisai_all_srcs "${ONNXRUNTIME_ROOT}/core/providers/vitisai/onnxruntime_providers_vitisai.rc")
endif()
onnxruntime_add_shared_library(onnxruntime_providers_vitisai ${onnxruntime_providers_vitisai_all_srcs})
if(WIN32)
# FILE_NAME preprocessor definition is used in onnxruntime_providers_vitisai.rc
target_compile_definitions(onnxruntime_providers_vitisai PRIVATE FILE_NAME=\"onnxruntime_providers_vitisai.dll\")
endif()
onnxruntime_add_include_to_target(onnxruntime_providers_vitisai ${ONNXRUNTIME_PROVIDERS_SHARED} ${GSL_TARGET} safeint_interface flatbuffers::flatbuffers Boost::mp11)
target_link_libraries(onnxruntime_providers_vitisai PRIVATE ${ONNXRUNTIME_PROVIDERS_SHARED} ${ABSEIL_LIBS})
if(MSVC)
Expand Down
341 changes: 0 additions & 341 deletions onnxruntime/contrib_ops/cpu/bert/attention_base.cc

This file was deleted.

316 changes: 315 additions & 1 deletion onnxruntime/contrib_ops/cpu/bert/attention_base.h

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions onnxruntime/contrib_ops/cpu/bert/attention_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ namespace contrib {

// Parameters deduced from node attributes and inputs/outputs.
struct AttentionParameters {
int batch_size;
int sequence_length;
int kv_sequence_length; // input sequence length of K or V
int past_sequence_length; // sequence length in past state of K or V
int total_sequence_length; // total sequence length of K or V
int max_sequence_length; // max sequence length from 4D mask
int input_hidden_size; // first dimension of weights for input projection
int hidden_size; // hidden size of Q or K
int head_size; // hidden size per head of Q or K
int v_hidden_size; // hidden size of V
int v_head_size; // hidden size per head of V
int num_heads;
int num_splits; // number of splits for splitkv
int batch_size = 0;
int sequence_length = 0;
int kv_sequence_length = 0; // input sequence length of K or V
int past_sequence_length = 0; // sequence length in past state of K or V
int total_sequence_length = 0; // total sequence length of K or V
int max_sequence_length = 0; // max sequence length from 4D mask
int input_hidden_size = 0; // first dimension of weights for input projection
int hidden_size = 0; // hidden size of Q or K
int head_size = 0; // hidden size per head of Q or K
int v_hidden_size = 0; // hidden size of V
int v_head_size = 0; // hidden size per head of V
int num_heads = 0;
int num_splits = 0; // number of splits for splitkv
int rotary_dim = 0; // rotary embedding dimension
int beam_width;
int beam_width = 0;
bool is_unidirectional = false;
bool past_present_share_buffer = false;
bool is_packed_qkv = false; // whether qkv is packed
bool do_rotary = false;
bool broadcast_attn_bias_dim_0 = false;
bool broadcast_attn_bias_dim_1 = false;
float mask_filter_value;
float scale;
float mask_filter_value = 0.0f;
float scale = 0.0f;
bool use_tf32 = false;
bool is_output_bnsh = false; // whether the output format is BNSH
AttentionMaskType mask_type;
AttentionQkvFormat qkv_format;
AttentionMaskType mask_type = AttentionMaskType::MASK_NONE;
AttentionQkvFormat qkv_format = AttentionQkvFormat::Q_K_V_BNSH;
};

// Parameters deduced from node attributes and inputs/outputs.
Expand Down
141 changes: 0 additions & 141 deletions onnxruntime/contrib_ops/cpu/bert/longformer_attention_base.cc

This file was deleted.

126 changes: 125 additions & 1 deletion onnxruntime/contrib_ops/cpu/bert/longformer_attention_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#pragma once

#include "core/common/common.h"
#ifndef SHARED_PROVIDER
#include "core/framework/op_kernel.h"
#endif

namespace onnxruntime {
namespace contrib {
Expand All @@ -20,7 +22,8 @@
const TensorShape& global_attention_mask_shape) const;

protected:
LongformerAttentionBase(const OpKernelInfo& info) {
template <typename KernelInfoType>
LongformerAttentionBase(const KernelInfoType& info) {

Check warning on line 26 in onnxruntime/contrib_ops/cpu/bert/longformer_attention_base.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Single-parameter constructors should be marked explicit. [runtime/explicit] [4] Raw Output: onnxruntime/contrib_ops/cpu/bert/longformer_attention_base.h:26: Single-parameter constructors should be marked explicit. [runtime/explicit] [4]
int64_t num_heads = 0;
ORT_ENFORCE(info.GetAttr("num_heads", &num_heads).IsOK() && num_heads > 0);
num_heads_ = static_cast<int>(num_heads);
Expand All @@ -43,5 +46,126 @@

} // namespace longformer

#ifndef SHARED_PROVIDER
// Inline implementation of CheckInputs for non-SHARED_PROVIDER builds.
inline Status LongformerAttentionBase::CheckInputs(const TensorShape& input_shape,
const TensorShape& weights_shape,
const TensorShape& bias_shape,
const TensorShape& attention_mask_shape,
const TensorShape& global_weights_shape,
const TensorShape& global_bias_shape,
const TensorShape& global_mask_shape) const {
const auto& dims = input_shape.GetDims();
if (dims.size() != 3) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input 'input' is expected to have 3 dimensions, got ",
dims.size());
}

int batch_size = static_cast<int>(dims[0]);
int sequence_length = static_cast<int>(dims[1]);
auto hidden_size = dims[2];
if (sequence_length % (2 * window_) != 0) {
return ORT_MAKE_STATUS(
ONNXRUNTIME, INVALID_ARGUMENT,
"Input 'input' dimension 1 should be divisible by 2W, where W is value of the window attribute.");
}
if (hidden_size % num_heads_ != 0) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT,
"Input 'input' dimension 2 should be divisible by value of the num_heads attribute.");
}

const auto& weights_dims = weights_shape.GetDims();
bool use_merged_qkv_weights = (weights_shape.NumDimensions() == 2);
if (use_merged_qkv_weights) {
if (weights_dims[0] != hidden_size || weights_dims[1] != 3 * hidden_size) {
return ORT_MAKE_STATUS(
ONNXRUNTIME, INVALID_ARGUMENT,
"Input 'weights' shape should be (hidden_size, 3 * hidden_size) for format 1");
}
} else {
if (weights_dims.size() != 3 ||
weights_dims[0] != 3 || weights_dims[1] != hidden_size || weights_dims[2] != hidden_size) {
return ORT_MAKE_STATUS(
ONNXRUNTIME, INVALID_ARGUMENT,
"Input 'weights' shape should be (3, hidden_size, hidden_size) for format 0");
}
}

const auto& bias_dims = bias_shape.GetDims();
if (bias_dims.size() != 1) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input 'bias' is expected to have 1 dimension, got ",
bias_dims.size());
}

if (use_merged_qkv_weights) {
if (bias_dims[0] != 3 * hidden_size) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT,
"Input 'bias' shape should be (3 * hidden_size) for format 1");
}
} else {
if (bias_dims[0] != 5 * hidden_size) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT,
"Input 'bias' shape should be (5 * hidden_size) for format 0");
}
}

const auto& mask_dims = attention_mask_shape.GetDims();
if (mask_dims.size() == 2) {
if (static_cast<int>(mask_dims[0]) != batch_size || static_cast<int>(mask_dims[1]) != sequence_length) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT,
"Inputs 'attention_mask' shape shall be (batch_size, sequence_length)");
}
} else {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT,
"Input 'attention_mask' is expected to have 2 dimensions, got ", mask_dims.size());
}

const auto& global_weights_dims = global_weights_shape.GetDims();
if (use_merged_qkv_weights) {
if (global_weights_dims.size() != 2 ||
global_weights_dims[0] != hidden_size || global_weights_dims[1] != 3 * hidden_size) {
return ORT_MAKE_STATUS(
ONNXRUNTIME, INVALID_ARGUMENT,
"Input 'global_weights' shape should be (hidden_size, 3 * hidden_size) for format 1");
}
} else {
if (global_weights_dims.size() != 3 || global_weights_dims[0] != 3 ||
global_weights_dims[1] != hidden_size || global_weights_dims[2] != hidden_size) {
return ORT_MAKE_STATUS(
ONNXRUNTIME, INVALID_ARGUMENT,
"Input 'global_weights' shape should be (3, hidden_size, hidden_size) for format 0");
}
}

const auto& global_bias_dims = global_bias_shape.GetDims();
if (global_bias_dims.size() != 1) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input 'global_bias' is expected to have 1 dimension, got ",
global_bias_dims.size());
}

if (use_merged_qkv_weights) {
if (global_bias_dims[0] != 3 * hidden_size) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT,
"Input 'global_bias' shape should be (3 * hidden_size) for format 1");
}
} else {
if (global_bias_dims[0] != hidden_size) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT,
"Input 'global_bias' shape should be (hidden_size) for format 0");
}
}

const auto& global_mask_dims = global_mask_shape.GetDims();
if (global_mask_dims.size() != 2 ||
static_cast<int>(global_mask_dims[0]) != batch_size ||
static_cast<int>(global_mask_dims[1]) != sequence_length) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT,
"Input 'global_attention_mask' shape shall be (batch_size, sequence_length)");
}

return Status::OK();
}
#endif // SHARED_PROVIDER

} // namespace contrib
} // namespace onnxruntime
9 changes: 6 additions & 3 deletions onnxruntime/contrib_ops/cpu/crop.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#pragma once

#include "core/common/common.h"
#ifndef SHARED_PROVIDER
#include "core/framework/op_kernel.h"
#endif

#include <gsl/gsl>

Expand All @@ -13,9 +15,10 @@

class CropBase {
protected:
CropBase(const OpKernelInfo& info)
: border_(info.GetAttrsOrDefault<int64_t>("border")),
scale_(info.GetAttrsOrDefault<int64_t>("scale")) {
template <typename KernelInfoType>
CropBase(const KernelInfoType& info)

Check warning on line 19 in onnxruntime/contrib_ops/cpu/crop.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Single-parameter constructors should be marked explicit. [runtime/explicit] [4] Raw Output: onnxruntime/contrib_ops/cpu/crop.h:19: Single-parameter constructors should be marked explicit. [runtime/explicit] [4]
: border_(info.template GetAttrsOrDefault<int64_t>("border")),
scale_(info.template GetAttrsOrDefault<int64_t>("scale")) {
}

Status ValidateInput(const Tensor* X) const {
Expand Down
Loading
Loading