Skip to content

Commit bc8519f

Browse files
Merge pull request #306 from microsoft/user/xianz/applyShareLib
User/xianz/apply share lib
2 parents c563979 + 0f5f662 commit bc8519f

File tree

13 files changed

+117
-234
lines changed

13 files changed

+117
-234
lines changed

Samples/AdapterSelection/AdapterSelection/cpp/AdapterSelection.vcxproj

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@
130130
<ConformanceMode>false</ConformanceMode>
131131
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
132132
<LanguageStandard>stdcpp17</LanguageStandard>
133-
<AdditionalIncludeDirectories>$(SolutionDir)\packages\rapidjson.v110.1.1.0\build\native\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
133+
<AdditionalIncludeDirectories>..\..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
134134
<CompileAsWinRT>false</CompileAsWinRT>
135135
</ClCompile>
136136
<Link>
137137
<SubSystem>Console</SubSystem>
138138
<GenerateDebugInformation>true</GenerateDebugInformation>
139-
<AdditionalDependencies>DXGI.lib;windowsapp.lib;ole32.lib;kernel32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
139+
<AdditionalDependencies>DXGI.lib;windowsapp.lib;ole32.lib;kernel32.lib;user32.lib;..\..\..\SampleSharedLib\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
140140
</Link>
141141
</ItemDefinitionGroup>
142142
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -149,11 +149,12 @@
149149
<ConformanceMode>true</ConformanceMode>
150150
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
151151
<LanguageStandard>stdcpp17</LanguageStandard>
152+
<AdditionalIncludeDirectories>..\..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
152153
</ClCompile>
153154
<Link>
154155
<SubSystem>Console</SubSystem>
155156
<GenerateDebugInformation>true</GenerateDebugInformation>
156-
<AdditionalDependencies>DXGI.lib;windowsapp.lib;ole32.lib;kernel32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
157+
<AdditionalDependencies>DXGI.lib;windowsapp.lib;ole32.lib;kernel32.lib;user32.lib;..\..\..\SampleSharedLib\x64\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
157158
</Link>
158159
</ItemDefinitionGroup>
159160
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
@@ -166,6 +167,7 @@
166167
<ConformanceMode>true</ConformanceMode>
167168
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
168169
<LanguageStandard>stdcpp17</LanguageStandard>
170+
<AdditionalIncludeDirectories>..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
169171
</ClCompile>
170172
<Link>
171173
<SubSystem>Console</SubSystem>
@@ -185,13 +187,14 @@
185187
<ConformanceMode>true</ConformanceMode>
186188
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
187189
<LanguageStandard>stdcpp17</LanguageStandard>
190+
<AdditionalIncludeDirectories>..\..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
188191
</ClCompile>
189192
<Link>
190193
<SubSystem>Console</SubSystem>
191194
<EnableCOMDATFolding>true</EnableCOMDATFolding>
192195
<OptimizeReferences>true</OptimizeReferences>
193196
<GenerateDebugInformation>true</GenerateDebugInformation>
194-
<AdditionalDependencies>DXGI.lib;windowsapp.lib;ole32.lib;kernel32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
197+
<AdditionalDependencies>DXGI.lib;windowsapp.lib;ole32.lib;kernel32.lib;user32.lib;..\..\..\SampleSharedLib\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
195198
</Link>
196199
</ItemDefinitionGroup>
197200
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -206,13 +209,14 @@
206209
<ConformanceMode>true</ConformanceMode>
207210
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
208211
<LanguageStandard>stdcpp17</LanguageStandard>
212+
<AdditionalIncludeDirectories>..\..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
209213
</ClCompile>
210214
<Link>
211215
<SubSystem>Console</SubSystem>
212216
<EnableCOMDATFolding>true</EnableCOMDATFolding>
213217
<OptimizeReferences>true</OptimizeReferences>
214218
<GenerateDebugInformation>true</GenerateDebugInformation>
215-
<AdditionalDependencies>DXGI.lib;windowsapp.lib;ole32.lib;kernel32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
219+
<AdditionalDependencies>DXGI.lib;windowsapp.lib;ole32.lib;kernel32.lib;user32.lib;..\..\..\SampleSharedLib\x64\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
216220
</Link>
217221
</ItemDefinitionGroup>
218222
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
@@ -227,6 +231,7 @@
227231
<ConformanceMode>true</ConformanceMode>
228232
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
229233
<LanguageStandard>stdcpp17</LanguageStandard>
234+
<AdditionalIncludeDirectories>..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
230235
</ClCompile>
231236
<Link>
232237
<SubSystem>Console</SubSystem>

Samples/AdapterSelection/AdapterSelection/cpp/main.cpp

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "pch.h"
2+
#include "FileHelper.h"
23

34
using namespace winrt;
45
using namespace Windows::Foundation::Collections;
@@ -15,9 +16,6 @@ hstring modelPath;
1516
hstring imagePath;
1617

1718
// helper functions
18-
string GetModulePath();
19-
void LoadLabels();
20-
VideoFrame LoadImageFile(hstring filePath);
2119
void PrintResults(IVectorView<float> results);
2220
bool ParseArgs(int argc, char* argv[]);
2321
LearningModelDevice getLearningModelDeviceFromAdapter(com_ptr<IDXGIAdapter1> spAdapter);
@@ -88,7 +86,7 @@ int main(int argc, char* argv[])
8886

8987
// load the image
9088
printf("Loading the image...\n");
91-
auto imageFrame = LoadImageFile(imagePath);
89+
auto imageFrame = FileHelper::LoadImageFile(imagePath);
9290

9391
// bind the input image
9492
printf("Binding...\n");
@@ -149,74 +147,12 @@ bool ParseArgs(int argc, char* argv[])
149147
return true;
150148
}
151149

152-
string GetModulePath()
153-
{
154-
string val;
155-
char modulePath[MAX_PATH] = {};
156-
GetModuleFileNameA(NULL, modulePath, ARRAYSIZE(modulePath));
157-
char drive[_MAX_DRIVE];
158-
char dir[_MAX_DIR];
159-
char filename[_MAX_FNAME];
160-
char ext[_MAX_EXT];
161-
_splitpath_s(modulePath, drive, _MAX_DRIVE, dir, _MAX_DIR, filename, _MAX_FNAME, ext, _MAX_EXT);
162-
163-
val = drive;
164-
val += dir;
165-
return val;
166-
}
167-
168-
void LoadLabels()
169-
{
170-
// Parse labels from labels file. We know the file's entries are already sorted in order.
171-
std::string labelsFilePath = GetModulePath() + labelsFileName;
172-
ifstream labelFile(labelsFilePath, ifstream::in);
173-
if (labelFile.fail())
174-
{
175-
printf("failed to load the %s file. Make sure it exists in the same folder as the app\r\n", labelsFileName.c_str());
176-
exit(EXIT_FAILURE);
177-
}
178-
179-
std::string s;
180-
while (std::getline(labelFile, s, ','))
181-
{
182-
int labelValue = atoi(s.c_str());
183-
if (labelValue >= static_cast<int>(labels.size()))
184-
{
185-
labels.resize(labelValue + 1);
186-
}
187-
std::getline(labelFile, s);
188-
labels[labelValue] = s;
189-
}
190-
}
191-
192-
VideoFrame LoadImageFile(hstring filePath)
193-
{
194-
try
195-
{
196-
// open the file
197-
StorageFile file = StorageFile::GetFileFromPathAsync(filePath).get();
198-
// get a stream on it
199-
auto stream = file.OpenAsync(FileAccessMode::Read).get();
200-
// Create the decoder from the stream
201-
BitmapDecoder decoder = BitmapDecoder::CreateAsync(stream).get();
202-
// get the bitmap
203-
SoftwareBitmap softwareBitmap = decoder.GetSoftwareBitmapAsync().get();
204-
// load a videoframe from it
205-
VideoFrame inputImage = VideoFrame::CreateWithSoftwareBitmap(softwareBitmap);
206-
// all done
207-
return inputImage;
208-
}
209-
catch (...)
210-
{
211-
printf("failed to load the image file, make sure you are using fully qualified paths\r\n");
212-
exit(EXIT_FAILURE);
213-
}
214-
}
215-
216150
void PrintResults(IVectorView<float> results)
217151
{
218152
// load the labels
219-
LoadLabels();
153+
auto modulePath = FileHelper::GetModulePath();
154+
std::string labelsFilePath = std::string(modulePath.begin(), modulePath.end()) + labelsFileName;
155+
labels = FileHelper::LoadLabels(labelsFilePath);
220156

221157
vector<pair<float, uint32_t>> sortedResults;
222158
for (uint32_t i = 0; i < results.Size(); i++) {

Samples/BatchSupport/BatchSupport/SampleHelper.cpp

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,6 @@ SoftwareBitmapToFloatVector(SoftwareBitmap softwareBitmap) {
6565
return outputVector;
6666
}
6767

68-
VideoFrame LoadImageFile(hstring filePath) {
69-
VideoFrame inputImage = nullptr;
70-
try {
71-
// open the file
72-
StorageFile file = StorageFile::GetFileFromPathAsync(filePath).get();
73-
// get a stream on it
74-
auto stream = file.OpenAsync(FileAccessMode::Read).get();
75-
// Create the decoder from the stream
76-
BitmapDecoder decoder = BitmapDecoder::CreateAsync(stream).get();
77-
// get the bitmap
78-
SoftwareBitmap softwareBitmap = decoder.GetSoftwareBitmapAsync().get();
79-
// load a videoframe from it
80-
inputImage = VideoFrame::CreateWithSoftwareBitmap(softwareBitmap);
81-
} catch (...) {
82-
printf("failed to load the image file, make sure you are using fully "
83-
"qualified paths\r\n");
84-
exit(EXIT_FAILURE);
85-
}
86-
// all done
87-
return inputImage;
88-
}
89-
9068
hstring GetModelPath(std::string modelType) {
9169
hstring modelPath;
9270
if (modelType == "fixedBatchSize") {
@@ -104,7 +82,7 @@ TensorFloat CreateInputTensorFloat() {
10482
std::vector<float> inputVector = {};
10583
for (hstring imageName : imageNames) {
10684
auto imagePath = static_cast<hstring>(FileHelper::GetModulePath().c_str()) + imageName;
107-
auto imageFrame = LoadImageFile(imagePath);
85+
auto imageFrame = FileHelper::LoadImageFile(imagePath);
10886
std::vector<float> imageVector =
10987
SoftwareBitmapToFloatVector(imageFrame.SoftwareBitmap());
11088
inputVector.insert(inputVector.end(), imageVector.begin(), imageVector.end());
@@ -124,44 +102,19 @@ IVector<VideoFrame> CreateVideoFrames() {
124102
std::vector<VideoFrame> inputFrames = {};
125103
for (hstring imageName : imageNames) {
126104
auto imagePath = static_cast<hstring>(FileHelper::GetModulePath().c_str()) + imageName;
127-
auto imageFrame = LoadImageFile(imagePath);
105+
auto imageFrame = FileHelper::LoadImageFile(imagePath);
128106
inputFrames.emplace_back(imageFrame);
129107
}
130108
auto videoFrames = winrt::single_threaded_vector(std::move(inputFrames));
131109
return videoFrames;
132110
}
133111

134-
std::vector<std::string> LoadLabels(std::string labelsFilePath) {
135-
// Parse labels from labels file. We know the file's entries are already
136-
// sorted in order.
137-
std::vector<std::string> labels;
138-
std::ifstream labelFile{labelsFilePath, std::ifstream::in};
139-
if (labelFile.fail()) {
140-
printf("failed to load the %s file. Make sure it exists in the same "
141-
"folder as the app\r\n",
142-
labelsFilePath.c_str());
143-
exit(EXIT_FAILURE);
144-
}
145-
146-
std::string s;
147-
while (std::getline(labelFile, s, ',')) {
148-
int labelValue = atoi(s.c_str());
149-
if (labelValue >= labels.size()) {
150-
labels.resize(labelValue + 1);
151-
}
152-
std::getline(labelFile, s);
153-
labels[labelValue] = s;
154-
}
155-
156-
return labels;
157-
}
158-
159112
void PrintResults(IVectorView<float> results) {
160113
// load the labels
161114
auto modulePath = FileHelper::GetModulePath();
162115
std::string labelsFilePath =
163116
std::string(modulePath.begin(), modulePath.end()) + "Labels.txt";
164-
std::vector<std::string> labels = LoadLabels(labelsFilePath);
117+
std::vector<std::string> labels = FileHelper::LoadLabels(labelsFilePath);
165118
// SqueezeNet returns a list of 1000 options, with probabilities for each,
166119
// loop through all
167120
for (uint32_t batchId = 0; batchId < BATCH_SIZE; ++batchId) {

Samples/BatchSupport/BatchSupport/SampleHelper.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ namespace SampleHelper
1212
std::vector<float> SoftwareBitmapToFloatVector(
1313
winrt::Windows::Graphics::Imaging::SoftwareBitmap softwareBitmap);
1414

15-
// Load Image File as VideoFrame
16-
winrt::Windows::Media::VideoFrame LoadImageFile(
17-
winrt::hstring filePath);
18-
19-
// Load object detection labels
20-
std::vector<std::string> LoadLabels(std::string labelsFilePath);
21-
2215
// Create input Tensorfloats with 3 images.
2316
winrt::Windows::AI::MachineLearning::TensorFloat CreateInputTensorFloat();
2417

Samples/CustomOperator/desktop/cpp/custom-operator-sample.vcxproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,23 @@
234234
</ImportGroup>
235235
<ItemDefinitionGroup>
236236
<ClCompile>
237-
<AdditionalIncludeDirectories>$(SolutionDir)\packages\rapidjson.v110.1.1.0\build\native\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
237+
<AdditionalIncludeDirectories>$(SolutionDir)\packages\rapidjson.v110.1.1.0\build\native\include\;..\..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
238238
</ClCompile>
239239
<ResourceCompile>
240240
<AdditionalIncludeDirectories>$(SolutionDir)\packages\rapidjson.v110.1.1.0\build\native\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
241241
</ResourceCompile>
242242
<Link>
243-
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
243+
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;..\..\..\SampleSharedLib\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
244244
</Link>
245245
<Link>
246-
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
246+
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;..\..\..\SampleSharedLib\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
247247
</Link>
248248
<Link>
249-
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
249+
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;..\..\..\SampleSharedLib\x64\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
250250
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
251251
</Link>
252252
<Link>
253-
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
253+
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;..\..\..\SampleSharedLib\x64\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
254254
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
255255
</Link>
256256
</ItemDefinitionGroup>

0 commit comments

Comments
 (0)