Skip to content

Commit

Permalink
Fix WinML warnings (microsoft#5228)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoshibata authored and tianleiwu committed Oct 12, 2020
1 parent 4227dd7 commit d77241e
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 31 deletions.
1 change: 1 addition & 0 deletions cmake/winml_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ file(GLOB winml_test_common_src CONFIGURE_DEPENDS
"${WINML_TEST_SRC_DIR}/common/*.h"
"${WINML_TEST_SRC_DIR}/common/*.cpp")
add_library(winml_test_common STATIC ${winml_test_common_src})
target_compile_options(winml_test_common PRIVATE /wd5205) # workaround cppwinrt SDK bug https://github.com/microsoft/cppwinrt/issues/584
add_dependencies(winml_test_common
onnx
winml_api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,8 @@ namespace OperatorHelper
// Determine the number of output dimensions.
ML_CHECK_VALID_ARGUMENT(inputDimensions.size() >= 1);
ML_CHECK_VALID_ARGUMENT(indicesDimensions.size() >= 1);
ML_CHECK_VALID_ARGUMENT(inputDimensions.size() > batchCount);
ML_CHECK_VALID_ARGUMENT(indicesDimensions.size() > batchCount);
ML_CHECK_VALID_ARGUMENT(static_cast<int64_t>(inputDimensions.size()) > static_cast<int64_t>(batchCount));
ML_CHECK_VALID_ARGUMENT(static_cast<int64_t>(indicesDimensions.size()) > static_cast<int64_t>(batchCount));
const uint32_t numberOfCoordinatesPerIndex = indicesDimensions.back();
ML_CHECK_VALID_ARGUMENT(inputDimensions.size() >= batchCount + numberOfCoordinatesPerIndex);
const uint32_t numberOfOutputDimensionsFromInput = static_cast<uint32_t>(inputDimensions.size()) - batchCount - numberOfCoordinatesPerIndex;
Expand Down
10 changes: 5 additions & 5 deletions winml/lib/Api.Image/NominalRangeConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ namespace _winml {
}

DirectX::PackedVector::HALF NominalRangeConverter::Normalize(DirectX::PackedVector::HALF val) const {
return val / scale - shift;
return static_cast<DirectX::PackedVector::HALF>(val / scale - shift);
}

#if defined(_M_AMD64) || defined(_M_IX86)
__m128 NominalRangeConverter::Normalize(__m128 sse_data) const {
__m128 sse_shift = _mm_set1_ps(shift);
__m128 sse_shift = _mm_set1_ps(static_cast<float>(shift));
__m128 sse_scale = _mm_set1_ps(scale);

auto sse_dived = _mm_div_ps(sse_data, sse_scale);
Expand All @@ -48,16 +48,16 @@ namespace _winml {
}

DirectX::PackedVector::HALF NominalRangeConverter::Denormalize(DirectX::PackedVector::HALF val) const {
return scale * (val + shift);
return static_cast<DirectX::PackedVector::HALF>(scale * (val + shift));
}

#if defined(_M_AMD64) || defined(_M_IX86)
__m128 NominalRangeConverter::Denormalize(__m128 sse_data) const {
__m128 sse_shift = _mm_set1_ps(shift);
__m128 sse_shift = _mm_set1_ps(static_cast<float>(shift));
__m128 sse_scale = _mm_set1_ps(scale);

auto sse_added = _mm_add_ps(sse_data, sse_shift);
return _mm_mul_ps(sse_added, sse_scale);
}
#endif
} // namespace _winml
} // namespace _winml
4 changes: 2 additions & 2 deletions winml/test/adapter/AdapterSessionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void CopyInputAcrossDevices() {
constexpr size_t input_tensor_size = [&dimensions]() {
size_t size = 1;
for (auto dim : dimensions)
size *= dim;
size *= static_cast<size_t>(dim);
return size;
} ();

Expand Down Expand Up @@ -259,7 +259,7 @@ void CopyInputAcrossDevices_DML() {
constexpr size_t input_tensor_size = [&dimensions]() {
size_t size = 1;
for (auto dim : dimensions)
size *= dim;
size *= static_cast<size_t>(dim);
return size;
} ();

Expand Down
20 changes: 10 additions & 10 deletions winml/test/adapter/adapter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ static void ModelGetVersion() {
static void ModelGetInputCount() {
size_t input_count;
winml_adapter_api->ModelGetInputCount(squeezenet_model, &input_count);
WINML_EXPECT_EQUAL(input_count, 1);
WINML_EXPECT_EQUAL(input_count, 1u);
}

static void ModelGetOutputCount() {
size_t output_count;
winml_adapter_api->ModelGetOutputCount(squeezenet_model, &output_count);
WINML_EXPECT_EQUAL(output_count, 1);
WINML_EXPECT_EQUAL(output_count, 1u);
}

static void ModelGetInputName() {
Expand Down Expand Up @@ -163,7 +163,7 @@ static void ModelGetInputTypeInfo() {

size_t dim_count;
ort_api->GetDimensionsCount(tensor_info, &dim_count);
WINML_EXPECT_EQUAL(dim_count, 4);
WINML_EXPECT_EQUAL(dim_count, 4u);

int64_t dim_values[4];
ort_api->GetDimensions(tensor_info, dim_values, 4);
Expand Down Expand Up @@ -192,7 +192,7 @@ static void ModelGetOutputTypeInfo() {

size_t dim_count;
ort_api->GetDimensionsCount(tensor_info, &dim_count);
WINML_EXPECT_EQUAL(dim_count, 4);
WINML_EXPECT_EQUAL(dim_count, 4u);

int64_t dim_values[4];
ort_api->GetDimensions(tensor_info, dim_values, 4);
Expand All @@ -207,7 +207,7 @@ static void ModelGetOutputTypeInfo() {
static void ModelGetMetadataCount() {
size_t metadata_count;
winml_adapter_api->ModelGetMetadataCount(metadata_model, &metadata_count);
WINML_EXPECT_EQUAL(metadata_count, 2);
WINML_EXPECT_EQUAL(metadata_count, 2u);
}

static void ModelGetMetadata() {
Expand All @@ -218,15 +218,15 @@ static void ModelGetMetadata() {

winml_adapter_api->ModelGetMetadata(metadata_model, 0, &metadata_key, &metadata_key_len, &metadata_value, &metadata_value_len);
WINML_EXPECT_EQUAL(std::string(metadata_key), "thisisalongkey");
WINML_EXPECT_EQUAL(metadata_key_len, 14);
WINML_EXPECT_EQUAL(metadata_key_len, 14u);
WINML_EXPECT_EQUAL(std::string(metadata_value), "thisisalongvalue");
WINML_EXPECT_EQUAL(metadata_value_len, 16);
WINML_EXPECT_EQUAL(metadata_value_len, 16u);

winml_adapter_api->ModelGetMetadata(metadata_model, 1, &metadata_key, &metadata_key_len, &metadata_value, &metadata_value_len);
WINML_EXPECT_EQUAL(std::string(metadata_key), "key2");
WINML_EXPECT_EQUAL(metadata_key_len, 4);
WINML_EXPECT_EQUAL(metadata_key_len, 4u);
WINML_EXPECT_EQUAL(std::string(metadata_value), "val2");
WINML_EXPECT_EQUAL(metadata_value_len, 4);
WINML_EXPECT_EQUAL(metadata_value_len, 4u);
}

static void ModelEnsureNoFloat16() {
Expand Down Expand Up @@ -328,4 +328,4 @@ const AdapterTestApi& getapi() {
EnvConfigureCustomLoggerAndProfiler,
};
return api;
}
}
5 changes: 2 additions & 3 deletions winml/test/api/LearningModelAPITest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void CreateModelFromFilePath() {

static void CreateModelFromUnicodeFilePath() {
LearningModel learningModel = nullptr;
WINML_EXPECT_NO_THROW(APITest::LoadModel(L"UnicodePath\\こんにちは maçã\\foo.onnx", learningModel));
WINML_EXPECT_NO_THROW(APITest::LoadModel(L"UnicodePath\\\u3053\u3093\u306B\u3061\u306F maçã\\foo.onnx", learningModel));
}

static void CreateModelFileNotFound() {
Expand All @@ -45,7 +45,6 @@ static void CreateCorruptModel() {
APITest::LoadModel(L"corrupt-model.onnx", learningModel),
winrt::hresult_error,
[](const winrt::hresult_error& e) -> bool {
auto f = __HRESULT_FROM_WIN32(e.code());
return e.code() == __HRESULT_FROM_WIN32(ERROR_FILE_CORRUPT);
});
}
Expand Down Expand Up @@ -309,4 +308,4 @@ const LearningModelApiTestsApi& getapi() {
api.CloseModelCheckEval = SkipTest;
}
return api;
}
}
3 changes: 2 additions & 1 deletion winml/test/api/LearningModelSessionAPITest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ static void NamedDimensionOverride()
WINML_EXPECT_NO_THROW(device = LearningModelDevice(LearningModelDeviceKind::Cpu));

// the model input shape. the batch size, n, is overriden to 5
int64_t n = 5, c = 3, h = 720, w = 720;
uint32_t n = 5;
int64_t c = 3, h = 720, w = 720;

LearningModelSessionOptions options;
options.OverrideNamedDimension(L"None", n);
Expand Down
8 changes: 3 additions & 5 deletions winml/test/api/RawApiTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ auto CreateModelAsBuffer(const wchar_t* model_path)
std::streamsize size = input_stream.tellg();
input_stream.seekg(0, std::ios::beg);

std::vector<char> buffer(size);
std::vector<char> buffer(static_cast<std::vector<char>::size_type>(size));
input_stream.read(buffer.data(), size);

return std::make_pair(buffer, size);
Expand Down Expand Up @@ -68,12 +68,10 @@ static void EvaluateNoInputCopy() {
static void EvaluateFromModelFromBuffer() {
std::wstring model_path = L"model.onnx";

size_t size;
std::vector<char> buffer;
std::tie(buffer, size) = CreateModelAsBuffer(model_path.c_str());
auto [buffer, size] = CreateModelAsBuffer(model_path.c_str());

std::unique_ptr<ml::learning_model> model = nullptr;
WINML_EXPECT_NO_THROW(model = std::make_unique<ml::learning_model>(buffer.data(), size));
WINML_EXPECT_NO_THROW(model = std::make_unique<ml::learning_model>(buffer.data(), static_cast<size_t>(size)));

std::unique_ptr<ml::learning_model_device> device = nullptr;
WINML_EXPECT_NO_THROW(device = std::make_unique<ml::learning_model_device>());
Expand Down
7 changes: 6 additions & 1 deletion winml/test/common/googleTestMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,17 @@
#define WINML_EXPECT_HRESULT_FAILED(hresult_expression) EXPECT_HRESULT_FAILED(hresult_expression)
#define WINML_EXPECT_THROW_SPECIFIC(statement, exception, condition) EXPECT_THROW_SPECIFIC(statement, exception, condition)

#pragma warning(push)
#pragma warning(disable:4505) // unreferenced local function has been removed

static bool RuntimeParameterExists(std::wstring param)
{
std::string narrowParam = std::wstring_convert<std::codecvt_utf8<wchar_t>>().to_bytes(param);
auto no_gpu_tests = RuntimeParameters::Parameters.find(narrowParam);
return no_gpu_tests != RuntimeParameters::Parameters.end() && no_gpu_tests->second != "0";
}

static bool SkipGpuTests()
static bool SkipGpuTests()
{
#ifndef USE_DML
return true;
Expand All @@ -110,3 +113,5 @@ static bool SkipTestsImpactedByOpenMP() {
return false;
#endif
}

#pragma warning(pop)
3 changes: 3 additions & 0 deletions winml/test/common/protobufHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ std::vector<int64_t> GetTypeSpecificDataFromTensorProto(
template <>
std::vector<uint8_t> GetTypeSpecificDataFromTensorProto(
onnx::TensorProto tensorProto) {
#pragma warning(push)
#pragma warning(disable:4244) // conversion with possible loss of data
return std::vector<uint8_t>(std::begin(tensorProto.int32_data()), std::end(tensorProto.int32_data()));
#pragma warning(pop)
}
template <>
std::vector<double> GetTypeSpecificDataFromTensorProto(
Expand Down
5 changes: 5 additions & 0 deletions winml/test/common/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ using TeardownClass = VoidTest;
using SetupTest = VoidTest;
using TeardownTest = VoidTest;

#pragma warning(push)
#pragma warning(disable:4505) // unreferenced local function has been removed

constexpr bool alwaysTrue() {
return true;
}
Expand All @@ -27,3 +30,5 @@ constexpr bool alwaysFalse() {
static void SkipTest() {
WINML_SKIP_TEST("");
}

#pragma warning(pop)
4 changes: 2 additions & 2 deletions winml/test/image/imageTestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ namespace ImageTestHelper {
// Copy from Cpu to GPU
D3D12_SUBRESOURCE_DATA CPUData = {};
CPUData.pData = reinterpret_cast<BYTE*>(pCPUTensor);
CPUData.RowPitch = bufferbytesize;
CPUData.SlicePitch = bufferbytesize;
CPUData.RowPitch = static_cast<LONG_PTR>(bufferbytesize);
CPUData.SlicePitch = static_cast<LONG_PTR>(bufferbytesize);
UpdateSubresources(cmdList.get(), pGPUResource.get(), imageUploadHeap.get(), 0, 0, 1, &CPUData);

// Close the command list and execute it to begin the initial GPU setup.
Expand Down

0 comments on commit d77241e

Please sign in to comment.