Skip to content

Commit

Permalink
fix some lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
amarin16 committed Sep 30, 2024
1 parent 405a0a0 commit 245f298
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
18 changes: 6 additions & 12 deletions onnxruntime/contrib_ops/cpu/skip_layer_norm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,15 @@ REGISTER_KERNEL_TYPED(MLFloat16)

namespace {

ORT_FORCEINLINE double* CreateBufferIfMLFloat16(double* p_output, int num_elems)
{
ORT_FORCEINLINE double* CreateBufferIfMLFloat16(double* p_output, int num_elems) {
return p_output;
}

ORT_FORCEINLINE float* CreateBufferIfMLFloat16(float* p_output, int num_elems)
{
ORT_FORCEINLINE float* CreateBufferIfMLFloat16(float* p_output, int num_elems) {
return p_output;
}

ORT_FORCEINLINE float* CreateBufferIfMLFloat16(MLFloat16* p_output, int num_elems)
{
ORT_FORCEINLINE float* CreateBufferIfMLFloat16(MLFloat16* p_output, int num_elems) {
return p_output == nullptr ? nullptr : new float[num_elems];
}

Expand All @@ -61,14 +58,12 @@ ORT_FORCEINLINE std::shared_ptr<std::vector<float>> ConvertHalfToFloatBufferIfNe

template <typename T>
ORT_FORCEINLINE std::shared_ptr<std::vector<float>> ConvertHalfToFloatBufferIfNeeded(
const std::enable_if_t<std::is_same_v<T,float> || std::is_same_v<T, double>, T>* p_input, int num_elems)
{
const std::enable_if_t<std::is_same_v<T,float> || std::is_same_v<T, double>, T>* p_input, int num_elems) {
return nullptr;
}

template<>
std::shared_ptr<std::vector<float>> ConvertHalfToFloatBufferIfNeeded<MLFloat16>(const MLFloat16* p_input, int num_elems)
{
std::shared_ptr<std::vector<float>> ConvertHalfToFloatBufferIfNeeded<MLFloat16>(const MLFloat16* p_input, int num_elems) {
if (!p_input) {
return nullptr;
}
Expand All @@ -81,8 +76,7 @@ std::shared_ptr<std::vector<float>> ConvertHalfToFloatBufferIfNeeded<MLFloat16>(
}


void ConvertFloatBufferToMLFloat16(const float* output_buffer, MLFloat16* p_output, int num_elems)
{
void ConvertFloatBufferToMLFloat16(const float* output_buffer, MLFloat16* p_output, int num_elems) {
if (!output_buffer || !p_output) {
return;
}
Expand Down
20 changes: 7 additions & 13 deletions onnxruntime/core/providers/cpu/nn/layer_norm_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,30 @@ namespace onnxruntime {

namespace {

ORT_FORCEINLINE double* OnlyCreateBufferIfMLFloat16(double* p_output, int num_elems)
{
ORT_FORCEINLINE double* OnlyCreateBufferIfMLFloat16(double* p_output, int num_elems) {
return p_output;
}

ORT_FORCEINLINE float* OnlyCreateBufferIfMLFloat16(float* p_output, int num_elems)
{
ORT_FORCEINLINE float* OnlyCreateBufferIfMLFloat16(float* p_output, int num_elems) {
return p_output;
}

ORT_FORCEINLINE float* OnlyCreateBufferIfMLFloat16(MLFloat16* p_output, int num_elems)
{
ORT_FORCEINLINE float* OnlyCreateBufferIfMLFloat16(MLFloat16* p_output, int num_elems) {
return p_output == nullptr ? nullptr : new float[num_elems];
}


template <typename T>
ORT_FORCEINLINE std::shared_ptr<std::vector<float>> ConvertMLFloat16ToFloatBufferIfNeeded(const T* p_input, int num_elems);
ORT_FORCEINLINE std::shared_ptr<std::vector<float>> ConvertMLFloat16ToFloatBufferIfNeeded(const T* p_input, int64_t num_elems);

template <typename T>
ORT_FORCEINLINE std::shared_ptr<std::vector<float>> ConvertMLFloat16ToFloatBufferIfNeeded(
const std::enable_if_t<std::is_same_v<T, float> || std::is_same_v<T, double>, T>* p_input, int num_elems)
{
const std::enable_if_t<std::is_same_v<T, float> || std::is_same_v<T, double>, T>* p_input, int64_t num_elems) {
return nullptr;
}

template<>
std::shared_ptr<std::vector<float>> ConvertMLFloat16ToFloatBufferIfNeeded<MLFloat16>(const MLFloat16* p_input, int num_elems)
{
std::shared_ptr<std::vector<float>> ConvertMLFloat16ToFloatBufferIfNeeded<MLFloat16>(const MLFloat16* p_input, int64_t num_elems) {
if (!p_input) {
return nullptr;
}
Expand All @@ -56,8 +51,7 @@ std::shared_ptr<std::vector<float>> ConvertMLFloat16ToFloatBufferIfNeeded<MLFloa
}


void ConvertFloatBufferToMLFloat16(const float* output_buffer, MLFloat16* p_output, int num_elems)
{
void ConvertFloatBufferToMLFloat16(const float* output_buffer, MLFloat16* p_output, int64_t num_elems) {
if (!output_buffer || !p_output) {
return;
}
Expand Down

0 comments on commit 245f298

Please sign in to comment.