Skip to content

Commit

Permalink
Fix clang-format comment indents on Windows for winml/ (microsoft#17144)
Browse files Browse the repository at this point in the history
On Windows, clang-format has a bug when AlignTrailingComments.Kind is
set to `Leave`
(https://clang.llvm.org/docs/ClangFormatStyleOptions.html#aligntrailingcomments),
where it will keep adding indentation to comments after each formatting
runs.

This PR changes to always align comments so we do not hit the bug.

As a consequence of the options change we need to reformat some of the
files. Note that this option is aligned with the rest of the repository.
  • Loading branch information
justinchuby authored Aug 15, 2023
1 parent 24e0bd3 commit 416dc2e
Show file tree
Hide file tree
Showing 58 changed files with 304 additions and 304 deletions.
2 changes: 1 addition & 1 deletion winml/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ AlignConsecutiveMacros:
AlignEscapedNewlines: Left
AlignOperands: DontAlign
AlignTrailingComments:
Kind: Leave
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
Expand Down
14 changes: 7 additions & 7 deletions winml/adapter/winml_adapter_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const OrtApi* GetVersion1Api();
namespace winmla = Windows::AI::MachineLearning::Adapter;

static constexpr WinmlAdapterApi winml_adapter_api_1 = {
// Schema override
// Schema override
&winmla::OverrideSchema,

// OrtEnv methods
// OrtEnv methods
&winmla::EnvConfigureCustomLoggerAndProfiler,

// OrtModel methods
// OrtModel methods
&winmla::CreateModelFromPath,
&winmla::CreateModelFromData,
&winmla::CloneModel,
Expand All @@ -43,11 +43,11 @@ static constexpr WinmlAdapterApi winml_adapter_api_1 = {
&winmla::ModelEnsureNoFloat16,
&winmla::SaveModel,

// OrtSessionOptions methods
// OrtSessionOptions methods
&OrtSessionOptionsAppendExecutionProvider_CPU,
&winmla::OrtSessionOptionsAppendExecutionProviderEx_DML,

// OrtSession methods
// OrtSession methods
&winmla::CreateSessionWithoutModel,
&winmla::SessionGetExecutionProvider,
&winmla::SessionInitialize,
Expand All @@ -61,7 +61,7 @@ static constexpr WinmlAdapterApi winml_adapter_api_1 = {
&winmla::SessionGetIntraOpThreadSpinning,
&winmla::SessionGetNamedDimensionsOverrides,

// Dml methods (TODO need to figure out how these need to move to session somehow...)
// Dml methods (TODO need to figure out how these need to move to session somehow...)
&winmla::DmlExecutionProviderFlushContext,
&winmla::DmlExecutionProviderReleaseCompletedReferences,
&winmla::DmlCopyTensor,
Expand Down Expand Up @@ -93,7 +93,7 @@ static constexpr WinmlAdapterApi winml_adapter_api_1 = {
&winmla::JoinModels,
&winmla::CreateThreadPool,

// Release
// Release
&winmla::ReleaseModel,
&winmla::ReleaseThreadPool,
};
Expand Down
6 changes: 3 additions & 3 deletions winml/adapter/winml_adapter_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ struct WinmlAdapterApi {

// Dml methods (TODO need to figure out how these need to move to session somehow...)

/**
/**
* SessionGetNumberOfIntraOpThreads
* This api returns the number of intra operator threads set on the OrtSession.
*
Expand All @@ -392,7 +392,7 @@ struct WinmlAdapterApi {
OrtStatus*(ORT_API_CALL* SessionGetNumberOfIntraOpThreads)(_In_ OrtSession* session, _Out_ uint32_t* num_threads)
NO_EXCEPTION;

/**
/**
* SessionGetIntrapOpThreadSpinning
* This api returns false if the ort session options config entry "session.intra_op.allow_spinning" is set to "0", and true otherwise
*
Expand All @@ -401,7 +401,7 @@ struct WinmlAdapterApi {
OrtStatus*(ORT_API_CALL* SessionGetIntraOpThreadSpinning)(_In_ OrtSession* session, _Out_ bool* allow_spinning)
NO_EXCEPTION;

/**
/**
* SessionGetNamedDimensionsOverrides
* This api returns the named dimension overrides that are specified for this session
*
Expand Down
4 changes: 2 additions & 2 deletions winml/adapter/winml_adapter_dml.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Licensed under the MIT License.

#pragma once
#include "adapter/pch.h"
Expand Down Expand Up @@ -69,7 +69,7 @@ Microsoft::WRL::ComPtr<IDMLDevice> CreateDmlDevice(ID3D12Device* d3d12Device) {

namespace onnxruntime {
void DmlConfigureProviderFactoryMetacommandsEnabled(IExecutionProviderFactory* factory, bool metacommandsEnabled);
}// namespace onnxruntime
} // namespace onnxruntime

#endif // USE_DML

Expand Down
26 changes: 13 additions & 13 deletions winml/api/dualapipartitionattribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* File built with Microsoft(R) MIDLRT Compiler Engine Version 10.00.0228
*/

#pragma warning(disable : 4049) /* more than 64k source lines */
#pragma warning(disable : 4049) /* more than 64k source lines */

/* verify that the <rpcndr.h> version is high enough to compile this file*/
#ifndef __REQUIRED_RPCNDR_H_VERSION__
Expand Down Expand Up @@ -41,33 +41,33 @@
#if !defined(SPECIFIC_API_CONTRACT_DEFINITIONS)
#if !defined(WINDOWS_APPLICATIONMODEL_CALLS_CALLSPHONECONTRACT_VERSION)
#define WINDOWS_APPLICATIONMODEL_CALLS_CALLSPHONECONTRACT_VERSION 0x50000
#endif // defined(WINDOWS_APPLICATIONMODEL_CALLS_CALLSPHONECONTRACT_VERSION)
#endif // defined(WINDOWS_APPLICATIONMODEL_CALLS_CALLSPHONECONTRACT_VERSION)

#if !defined(WINDOWS_FOUNDATION_FOUNDATIONCONTRACT_VERSION)
#define WINDOWS_FOUNDATION_FOUNDATIONCONTRACT_VERSION 0x40000
#endif // defined(WINDOWS_FOUNDATION_FOUNDATIONCONTRACT_VERSION)
#endif // defined(WINDOWS_FOUNDATION_FOUNDATIONCONTRACT_VERSION)

#if !defined(WINDOWS_FOUNDATION_UNIVERSALAPICONTRACT_VERSION)
#define WINDOWS_FOUNDATION_UNIVERSALAPICONTRACT_VERSION 0xa0000
#endif // defined(WINDOWS_FOUNDATION_UNIVERSALAPICONTRACT_VERSION)
#endif // defined(WINDOWS_FOUNDATION_UNIVERSALAPICONTRACT_VERSION)

#if !defined(WINDOWS_NETWORKING_SOCKETS_CONTROLCHANNELTRIGGERCONTRACT_VERSION)
#define WINDOWS_NETWORKING_SOCKETS_CONTROLCHANNELTRIGGERCONTRACT_VERSION 0x30000
#endif // defined(WINDOWS_NETWORKING_SOCKETS_CONTROLCHANNELTRIGGERCONTRACT_VERSION)
#endif // defined(WINDOWS_NETWORKING_SOCKETS_CONTROLCHANNELTRIGGERCONTRACT_VERSION)

#if !defined(WINDOWS_PHONE_PHONECONTRACT_VERSION)
#define WINDOWS_PHONE_PHONECONTRACT_VERSION 0x10000
#endif // defined(WINDOWS_PHONE_PHONECONTRACT_VERSION)
#endif // defined(WINDOWS_PHONE_PHONECONTRACT_VERSION)

#if !defined(WINDOWS_PHONE_PHONEINTERNALCONTRACT_VERSION)
#define WINDOWS_PHONE_PHONEINTERNALCONTRACT_VERSION 0x10000
#endif // defined(WINDOWS_PHONE_PHONEINTERNALCONTRACT_VERSION)
#endif // defined(WINDOWS_PHONE_PHONEINTERNALCONTRACT_VERSION)

#if !defined(WINDOWS_UI_WEBUI_CORE_WEBUICOMMANDBARCONTRACT_VERSION)
#define WINDOWS_UI_WEBUI_CORE_WEBUICOMMANDBARCONTRACT_VERSION 0x10000
#endif // defined(WINDOWS_UI_WEBUI_CORE_WEBUICOMMANDBARCONTRACT_VERSION)
#endif // defined(WINDOWS_UI_WEBUI_CORE_WEBUICOMMANDBARCONTRACT_VERSION)

#endif // defined(SPECIFIC_API_CONTRACT_DEFINITIONS)
#endif // defined(SPECIFIC_API_CONTRACT_DEFINITIONS)

// Header files for imported files
#include "Windows.Foundation.h"
Expand All @@ -81,7 +81,7 @@
#pragma once
#pragma warning(pop)

#else // !defined(__cplusplus)
#else // !defined(__cplusplus)
/* Forward Declarations */

#pragma warning(push)
Expand All @@ -90,8 +90,8 @@
#pragma once
#pragma warning(pop)

#endif // defined(__cplusplus)
#endif // defined(__cplusplus)
#pragma pop_macro("MIDL_CONST_ID")
#endif // __dualapipartitionattribute_p_h__
#endif // __dualapipartitionattribute_p_h__

#endif // __dualapipartitionattribute_h__
#endif // __dualapipartitionattribute_h__
2 changes: 1 addition & 1 deletion winml/lib/Api.Experimental/LearningModelExperimental.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ void LearningModelExperimental::SetName(hstring const& model_name) {
modelp->SetName(model_name);
}

}// namespace WINML_EXPERIMENTALP
} // namespace WINML_EXPERIMENTALP
4 changes: 2 additions & 2 deletions winml/lib/Api.Experimental/LearningModelExperimental.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ struct LearningModelExperimental : LearningModelExperimentalT<LearningModelExper
Microsoft::AI::MachineLearning::LearningModel model_;
};

}// namespace WINML_EXPERIMENTALP
} // namespace WINML_EXPERIMENTALP

namespace WINML_EXPERIMENTAL::factory_implementation {

struct LearningModelExperimental
: LearningModelExperimentalT<LearningModelExperimental, implementation::LearningModelExperimental> {};

}// namespace WINML_EXPERIMENTAL::factory_implementation
} // namespace WINML_EXPERIMENTAL::factory_implementation
2 changes: 1 addition & 1 deletion winml/lib/Api.Experimental/LearningModelJoinOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ const std::unordered_map<std::string, std::string>& LearningModelJoinOptions::Ge
return linkages_;
}

}// namespace WINML_EXPERIMENTALP
} // namespace WINML_EXPERIMENTALP
2 changes: 1 addition & 1 deletion winml/lib/Api.Experimental/LearningModelJoinOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ namespace WINML_EXPERIMENTAL::factory_implementation {
struct LearningModelJoinOptions
: LearningModelJoinOptionsT<LearningModelJoinOptions, implementation::LearningModelJoinOptions> {};

}// namespace WINML_EXPERIMENTAL::factory_implementation
} // namespace WINML_EXPERIMENTAL::factory_implementation
4 changes: 2 additions & 2 deletions winml/lib/Api.Experimental/LearningModelOperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ struct LearningModelOperator : LearningModelOperatorT<LearningModelOperator> {
wfc::IMap<winrt::hstring, winrt::hstring> output_mapping_;
};

} // namespace WINML_EXPERIMENTALP
} // namespace WINML_EXPERIMENTALP

namespace WINML_EXPERIMENTAL::factory_implementation {

struct LearningModelOperator : LearningModelOperatorT<LearningModelOperator, implementation::LearningModelOperator> {};

}// namespace WINML_EXPERIMENTAL::factory_implementation
} // namespace WINML_EXPERIMENTAL::factory_implementation
2 changes: 1 addition & 1 deletion winml/lib/Api.Experimental/LearningModelOperatorSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ winml_experimental::LearningModelBuilder LearningModelOperatorSet::Add(
return builder_;
}

}// namespace WINML_EXPERIMENTALP
} // namespace WINML_EXPERIMENTALP
2 changes: 1 addition & 1 deletion winml/lib/Api.Experimental/LearningModelOperatorSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ struct LearningModelOperatorSet : LearningModelOperatorSetT<LearningModelOperato
winml_experimental::LearningModelBuilder builder_;
wfc::IVector<winml_experimental::LearningModelOperator> operators_;
};
}// namespace WINML_EXPERIMENTALP
} // namespace WINML_EXPERIMENTALP
2 changes: 1 addition & 1 deletion winml/lib/Api.Experimental/LearningModelOutputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ winml_experimental::LearningModelBuilder LearningModelOutputs::Add(winml::ILearn
return builder_;
}

} // namespace WINML_EXPERIMENTALP
} // namespace WINML_EXPERIMENTALP
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ struct LearningModelSessionOptionsExperimental : LearningModelSessionOptionsExpe
LearningModelSessionOptionsExperimental,
implementation::LearningModelSessionOptionsExperimental> {};

}// namespace WINML_EXPERIMENTAL::factory_implementation
} // namespace WINML_EXPERIMENTAL::factory_implementation
16 changes: 8 additions & 8 deletions winml/lib/Api.Image/DeviceHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ HRESULT _winml::GetDXCoreHardwareAdapterWithPreference(
HRESULT _winml::CreateD3D11On12Device(ID3D12Device* device12, ID3D11Device** device11) {
return CommonDeviceHelpers::RunDelayLoadedApi(
D3D11On12CreateDevice,
device12, // pointer to d3d12 device
device12, // pointer to d3d12 device
D3D11_CREATE_DEVICE_BGRA_SUPPORT, // required in order to interop with Direct2D
nullptr, // feature level (defaults to d3d12)
0, // size of feature levels in bytes
nullptr, // an array of unique command queues for D3D11On12 to use
0, // size of the command queue array
0, // D3D12 device node to use
device11, // d3d11 device out param
nullptr, // pointer to d3d11 device context (unused)
nullptr, // feature level (defaults to d3d12)
0, // size of feature levels in bytes
nullptr, // an array of unique command queues for D3D11On12 to use
0, // size of the command queue array
0, // D3D12 device node to use
device11, // d3d11 device out param
nullptr, // pointer to d3d11 device context (unused)
nullptr
); // pointer to the returned feature level (unused)
}
Expand Down
2 changes: 1 addition & 1 deletion winml/lib/Api.Image/DisjointBufferHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ void StoreSpanIntoDisjointBuffers(
LoadOrStoreDisjointBuffers(false /*store into buffers*/, num_buffers, get_buffer, buffer_span);
}

} // namespace _winml
} // namespace _winml
18 changes: 9 additions & 9 deletions winml/lib/Api.Image/NominalRangeConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace _winml {
NominalRangeConverter::NominalRangeConverter(winml::LearningModelPixelRange pixelRange) {
// For Normalization: the formula is input_range[min, max] / scale - shift
// For DeNormalization: the formula is (input_range[min, max] + shift) * scale
// For Normalization: the formula is input_range[min, max] / scale - shift
// For DeNormalization: the formula is (input_range[min, max] + shift) * scale
if (pixelRange == winml::LearningModelPixelRange::ZeroTo255) {
scale = 1.f;
shift = 0;
Expand All @@ -17,9 +17,9 @@ NominalRangeConverter::NominalRangeConverter(winml::LearningModelPixelRange pixe
}
};

// [0, 255] --> [0, 255]
// [0, 255] / 255 --> [0, 1]
// [0, 255] * 2 / 255 - 1 --> [-1, 1]
// [0, 255] --> [0, 255]
// [0, 255] / 255 --> [0, 1]
// [0, 255] * 2 / 255 - 1 --> [-1, 1]
float NominalRangeConverter::Normalize(float val) const {
return val / scale - shift;
}
Expand All @@ -38,9 +38,9 @@ __m128 NominalRangeConverter::Normalize(__m128 sse_data) const {
}
#endif

// [0, 255] --> [0, 255]
// ([0, 1] + 0 ) * 255 -> [0, 1]
// ([-1, 1] + 1) * 255 / 2 --> [-1, 1]
// [0, 255] --> [0, 255]
// ([0, 1] + 0 ) * 255 -> [0, 1]
// ([-1, 1] + 1) * 255 / 2 --> [-1, 1]
float NominalRangeConverter::Denormalize(float val) const {
return scale * (val + shift);
}
Expand All @@ -58,4 +58,4 @@ __m128 NominalRangeConverter::Denormalize(__m128 sse_data) const {
return _mm_mul_ps(sse_added, sse_scale);
}
#endif
} // namespace _winml
} // namespace _winml
2 changes: 1 addition & 1 deletion winml/lib/Api.Image/inc/DisjointBufferHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ void StoreSpanIntoDisjointBuffers(
size_t num_buffers, std::function<gsl::span<byte>(size_t)> get_buffer, gsl::span<byte>& buffer_span
);

} // namespace _winml
} // namespace _winml
2 changes: 1 addition & 1 deletion winml/lib/Api.Image/inc/NominalRangeConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ class NominalRangeConverter {
float scale;
int32_t shift;
};
} // namespace _winml
} // namespace _winml
6 changes: 3 additions & 3 deletions winml/lib/Api/FeatureValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ CREATE_TENSOR(TensorInt64Bit, int64_t, int64_t)
CREATE_TENSOR(TensorFloat16Bit, _winml::Half, float)

#pragma warning(push)
#pragma warning(disable : 4702) // Unreachable code (one of TensorBase's constructor unconditionally throws for \
#pragma warning(disable : 4702) // Unreachable code (one of TensorBase's constructor unconditionally throws for \
// std::string because it's not supported with D3D12 resources)
CREATE_TENSOR(TensorString, std::string, winrt::hstring)
#pragma warning(pop)
Expand Down Expand Up @@ -420,8 +420,8 @@ inline winml::ILearningModelFeatureValue CreateFeatureValueFromInspectable(
BindingType, const wf::IInspectable& inspectable, const winml::ITensorFeatureDescriptor& descriptor
);
constexpr std::array<TensorCreator, 13> creators = {
// Vector and VectorViews of float16 and int8 collide with float and uint8 respectively.
// They are omitted because of this ambiguity and are not constructible via raw winrt collections.
// Vector and VectorViews of float16 and int8 collide with float and uint8 respectively.
// They are omitted because of this ambiguity and are not constructible via raw winrt collections.
CreateTensorValueFromInspectable<winmlp::TensorBoolean, bool>,
CreateTensorValueFromInspectable<winmlp::TensorFloat, float>,
CreateTensorValueFromInspectable<winmlp::TensorDouble, double>,
Expand Down
2 changes: 1 addition & 1 deletion winml/lib/Api/ImageFeatureDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ImageColorSpaceGamma ImageFeatureDescriptor::GetColorSpaceGamma() {

HRESULT
ImageFeatureDescriptor::GetDescriptorInfo(_winml::IEngineFactory* engine_factory, _winml::IDescriptorInfo** info) {
// TODO: Need to add denotations here
// TODO: Need to add denotations here
engine_factory->CreateTensorDescriptorInfo(tensor_kind_, shape_.data(), shape_.size(), info);
return S_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion winml/lib/Api/ImageFeatureValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ std::optional<ImageFeatureValue::ImageResourceMetadata> ImageFeatureValue::GetIn
THROW_HR(WINML_ERR_INVALID_BINDING);
}

//NCHW layout
//NCHW layout
auto imageTensorDescriptor = CreateImageTensorDescriptor(
tensorKind, pixelFormat.value(), pixelRange.value(), m_batchSize, descriptorWidth, descriptorHeight
);
Expand Down
12 changes: 6 additions & 6 deletions winml/lib/Api/LearningModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ LearningModel::LearningModel(const hstring& path, const winml::ILearningModelOpe
0, // size of mapping object, high
0, // size of mapping object, low
NULL
)); // name of mapping object
)); // name of mapping object

WINML_THROW_HR_IF_TRUE_MSG(__HRESULT_FROM_WIN32(GetLastError()), file_mapping == nullptr, "Model load failed!");

auto buffer = MapViewOfFile(
file_mapping.get(), // handle to mapping object
FILE_MAP_READ, // read/write
0, // high-order 32 bits of file offset
0, // low-order 32 bits of file offset
file_mapping.get(), // handle to mapping object
FILE_MAP_READ, // read/write
0, // high-order 32 bits of file offset
0, // low-order 32 bits of file offset
0
); // number of bytes to map. 0 means read whole file.
); // number of bytes to map. 0 means read whole file.

WINML_THROW_HR_IF_TRUE_MSG(__HRESULT_FROM_WIN32(GetLastError()), buffer == nullptr, "Model load failed!");
LARGE_INTEGER file_size;
Expand Down
2 changes: 1 addition & 1 deletion winml/lib/Api/MapFeatureDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct MapFeatureDescriptor : MapFeatureDescriptorT<
winml::ILearningModelFeatureDescriptor valueKind
);

// IMapDescriptor
// IMapDescriptor
winml::TensorKind KeyKind();

winml::ILearningModelFeatureDescriptor ValueDescriptor();
Expand Down
Loading

0 comments on commit 416dc2e

Please sign in to comment.