Skip to content

Commit d4d419f

Browse files
authored
fix more dml warnings (#21980)
### Description Fixes more warnings in DML execution provider that lead to security issues in binskim ### Motivation and Context OS components that include ORT must treat certain warnings as errors, and cannot disable critical compiler warnings https://github.com/microsoft/binskim/blob/main/src/BinSkim.Rules/PERules/BA2007.EnableCriticalCompilerWarnings.cs
1 parent 93c4c9c commit d4d419f

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

onnxruntime/core/providers/dml/DmlExecutionProvider/src/DmlGraphFusionHelper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ namespace DmlGraphFusionHelper
368368

369369
DML_CONSTANT_DATA_GRAPH_NODE_DESC* constantNode = allocator.template Allocate<DML_CONSTANT_DATA_GRAPH_NODE_DESC>();
370370
constantNode->Name = node.Name.data();
371-
constantNode->DataSize = constantData.dataSize;
371+
constantNode->DataSize = gsl::narrow_cast<size_t>(constantData.dataSize);
372372
constantNode->Data = constantData.data;
373373
dmlGraphNodes.push_back(DML_GRAPH_NODE_DESC{DML_GRAPH_NODE_TYPE_CONSTANT, constantNode});
374374
}
@@ -845,11 +845,11 @@ namespace DmlGraphFusionHelper
845845
.Provider(onnxruntime::kDmlExecutionProvider);
846846

847847
// Force the CPU inputs to be allocated on the CPU
848-
for (int i = 0; i < subGraphInputArgNames.size(); ++i)
848+
for (size_t i = 0; i < subGraphInputArgNames.size(); ++i)
849849
{
850850
if (dynamicCpuInputMap.find(subGraphInputArgNames[i]) != dynamicCpuInputMap.end())
851851
{
852-
builder.InputMemoryType(OrtMemTypeCPUInput, i);
852+
builder.InputMemoryType(OrtMemTypeCPUInput, static_cast<int>(i));
853853
}
854854
}
855855

onnxruntime/core/providers/dml/DmlExecutionProvider/src/DmlRuntimeFusedGraphKernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ namespace Dml
122122
{
123123
if (initializerIter->second.first->raw_data().length() == inputProto.raw_data().length())
124124
{
125-
for (int i = 0; i < inputProto.raw_data().length(); ++i)
125+
for (size_t i = 0; i < inputProto.raw_data().length(); ++i)
126126
{
127127
if (initializerIter->second.first->raw_data()[i] != inputProto.raw_data()[i])
128128
{

onnxruntime/core/providers/dml/DmlExecutionProvider/src/GraphDescBuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ namespace Dml::GraphDescBuilder
333333
EdgeShapes inputShapesOverrides(node.InputDefs().size());
334334

335335
// Override the input shapes with shapes that were previously inferred
336-
for (int inputIndex = 0; inputIndex < node.InputDefs().size(); ++inputIndex)
336+
for (size_t inputIndex = 0; inputIndex < node.InputDefs().size(); ++inputIndex)
337337
{
338338
auto inputDef = node.InputDefs()[inputIndex];
339339

@@ -344,7 +344,8 @@ namespace Dml::GraphDescBuilder
344344
}
345345
else if (inputDef->HasTensorOrScalarShape())
346346
{
347-
for (int i = 0; i < inputDef->Shape()->dim_size(); ++i)
347+
int dimSize = gsl::narrow_cast<int>(inputDef->Shape()->dim_size());
348+
for (int i = 0; i < dimSize; ++i)
348349
{
349350
ORT_THROW_HR_IF(E_INVALIDARG, !inputDef->Shape()->dim(i).has_dim_value());
350351
inputShapesOverrides.GetMutableShape(inputIndex).push_back(gsl::narrow_cast<uint32_t>(inputDef->Shape()->dim(i).dim_value()));
@@ -364,7 +365,7 @@ namespace Dml::GraphDescBuilder
364365
);
365366

366367
ORT_THROW_HR_IF(E_UNEXPECTED, outputShapes.EdgeCount() != node.OutputDefs().size());
367-
for (int i = 0; i < node.OutputDefs().size(); ++i)
368+
for (size_t i = 0; i < node.OutputDefs().size(); ++i)
368369
{
369370
inferredOutputShapes[node.OutputDefs()[i]->Name()] = outputShapes.GetShape(i);
370371
}

onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorResize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void ComputePixelOffsetsAndScales(
6060
// Fill in all the input/output pixel offset for each axis,
6161
// and recompute the scale for certain modes.
6262

63-
for (uint64_t i = 0; i < rank; ++i)
63+
for (uint32_t i = 0; i < rank; ++i)
6464
{
6565
float inputPixelOffset = 0;
6666
float outputPixelOffset = 0;

onnxruntime/core/providers/dml/OperatorAuthorHelper/OperatorHelper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,11 +1149,11 @@ namespace OperatorHelper
11491149
HandleEmptyAxes(axes, inputShape, false);
11501150
}
11511151

1152-
uint32_t numAxes = gsl::narrow_cast<uint32_t>(axes.size());
1153-
for (int32_t i = 0; i < axes.size(); i++)
1152+
size_t numAxes = axes.size();
1153+
for (size_t i = 0; i < numAxes; i++)
11541154
{
11551155
auto xi_begin = padding[i];
1156-
auto xi_end = padding[i+axes.size()];
1156+
auto xi_end = padding[i+numAxes];
11571157
m_startPadding[axes[i]] = xi_begin;
11581158
m_endPadding[axes[i]] = xi_end;
11591159
}
@@ -1888,7 +1888,7 @@ namespace OperatorHelper
18881888
m_outputShape.resize(2 + m_imageShape.size());
18891889
m_outputShape[0] = m_inputShape[0]; // N
18901890
m_outputShape[1] = m_inputShape[1] / blockShapeProduct; // C
1891-
for (int i = 2; i < m_outputShape.size(); i++)
1891+
for (size_t i = 2; i < m_outputShape.size(); i++)
18921892
{
18931893
m_outputShape[i] = m_imageShape[i - 2];
18941894
};

0 commit comments

Comments
 (0)