Repository: microsoft/onnxruntime
File: onnxruntime/contrib_ops/cpu/skip_layer_norm.cc (C++)

Code before:

  if constexpr (std::is_same_v<T, MLFloat16>) {
    if (skip == nullptr) {
      std::cout << "missing skip";
    }
    const int64_t total_data_size = input->Shape().Size();

    AllocatorPtr alloc;
    ORT_RETURN_IF_ERROR(p_ctx->GetTempSpaceAllocator(&alloc));

    IAllocatorUniquePtr<float> input_fp32;
    IAllocatorUniquePtr<float> output_fp32;
    IAllocatorUniquePtr<float> skip_input_bias_add_output_fp32;
    IAllocatorUniquePtr<float> skip_fp32;
    IAllocatorUniquePtr<float> gamma_fp32;
    IAllocatorUniquePtr<float> beta_fp32;
    IAllocatorUniquePtr<float> bias_fp32;

    const float* input_data_f = nullptr;
    const float* skip_data_f = nullptr;
    const float* gamma_data_f = nullptr;
    const float* beta_data_f = nullptr;
    const float* bias_data_f = nullptr;
    float* output_data_f = nullptr;
    float* skip_input_bias_add_output_data_f = nullptr;

    const size_t num_elems = static_cast<size_t>(hidden_size);

    input_fp32 = IAllocator::MakeUniquePtr<float>(alloc, total_data_size);
    MlasConvertHalfToFloatBuffer(input_data, input_fp32.get(), total_data_size);
    input_data_f = input_fp32.get();

    output_fp32 = IAllocator::MakeUniquePtr<float>(alloc, total_data_size);
    output_data_f = output_fp32.get();

    skip_input_bias_add_output_fp32 = IAllocator::MakeUniquePtr<float>(alloc, total_data_size);
    skip_input_bias_add_output_data_f = skip_input_bias_add_output_fp32.get();

    if (skip_data) {
      skip_fp32 = IAllocator::MakeUniquePtr<float>(alloc, skip_size);
      MlasConvertHalfToFloatBuffer(skip_data, skip_fp32.get(), skip_size);
      skip_data_f = skip_fp32.get();
    } else if (prepacked_skip_fp32_data_) {
      skip_data_f = prepacked_skip_fp32_data_.get();
    }

    if (gamma_data) {
      gamma_fp32 = IAllocator::MakeUniquePtr<float>(alloc, num_elems);
      MlasConvertHalfToFloatBuffer(gamma_data, gamma_fp32.get(), num_elems);
      gamma_data_f = gamma_fp32.get();
    } else if (prepacked_gamma_fp32_data_) {

Review comment (bug):
might need a `static_cast<size_t>` here, one of the pipelines seems to be failing with
```
##[warning]onnxruntime\contrib_ops\cpu\skip_layer_norm.cc(191,58): Warning C4244: 'argument': conversion from 'const int64_t' to 'size_t', possible loss of data
```


Code after:

  if constexpr (std::is_same_v<T, MLFloat16>) {
    const size_t total_data_size = static_cast<size_t>(input->Shape().Size());

    AllocatorPtr alloc;
    ORT_RETURN_IF_ERROR(p_ctx->GetTempSpaceAllocator(&alloc));

    IAllocatorUniquePtr<float> input_fp32;
    IAllocatorUniquePtr<float> output_fp32;
    IAllocatorUniquePtr<float> skip_input_bias_add_output_fp32;
    IAllocatorUniquePtr<float> skip_fp32;
    IAllocatorUniquePtr<float> gamma_fp32;
    IAllocatorUniquePtr<float> beta_fp32;
    IAllocatorUniquePtr<float> bias_fp32;

    const float* input_data_f = nullptr;
    const float* skip_data_f = nullptr;
    const float* gamma_data_f = nullptr;
    const float* beta_data_f = nullptr;
    const float* bias_data_f = nullptr;
    float* output_data_f = nullptr;
    float* skip_input_bias_add_output_data_f = nullptr;

    const size_t num_elems = static_cast<size_t>(hidden_size);

    input_fp32 = IAllocator::MakeUniquePtr<float>(alloc, total_data_size);
    MlasConvertHalfToFloatBuffer(input_data, input_fp32.get(), total_data_size);
    input_data_f = input_fp32.get();

    output_fp32 = IAllocator::MakeUniquePtr<float>(alloc, total_data_size);
    output_data_f = output_fp32.get();

    skip_input_bias_add_output_fp32 = IAllocator::MakeUniquePtr<float>(alloc, total_data_size);
    skip_input_bias_add_output_data_f = skip_input_bias_add_output_fp32.get();

    if (skip_data) {
      skip_fp32 = IAllocator::MakeUniquePtr<float>(alloc, static_cast<size_t>(skip_size));
      MlasConvertHalfToFloatBuffer(skip_data, skip_fp32.get(), static_cast<size_t>(skip_size));
      skip_data_f = skip_fp32.get();
    } else if (prepacked_skip_fp32_data_) {
      skip_data_f = prepacked_skip_fp32_data_.get();
    }

    if (gamma_data) {
      gamma_fp32 = IAllocator::MakeUniquePtr<float>(alloc, num_elems);
      MlasConvertHalfToFloatBuffer(gamma_data, gamma_fp32.get(), num_elems);
      gamma_data_f = gamma_fp32.get();
    } else if (prepacked_gamma_fp32_data_) {
      gamma_data_f = prepacked_gamma_fp32_data_.get();
    }