Skip to content

Commit 101e603

Browse files
committed
fix ofstream binary issue for windows wang-xinyu#585
1 parent f8c5375 commit 101e603

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

alexnet/alex.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ int main(int argc, char** argv)
233233
APIToModel(1, &modelStream);
234234
assert(modelStream != nullptr);
235235

236-
std::ofstream p("alexnet.engine");
236+
std::ofstream p("alexnet.engine", std::ios::binary);
237237
if (!p)
238238
{
239239
std::cerr << "could not open plan output file" << std::endl;

inception/inceptionv4/inception_v4.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace trtx {
4444
builder -> destroy();
4545

4646
// write serialized engine to file
47-
std::ofstream trtFile(mParams.trtEngineFile);
47+
std::ofstream trtFile(mParams.trtEngineFile, std::ios::binary);
4848
if(!trtFile){
4949
std::cerr << "Unable to open engine file." << std::endl;
5050
return false;
@@ -193,26 +193,26 @@ namespace trtx {
193193
// Engine requires exactly IEngine::getNbBindings() number of buffers.
194194
assert(mEngine -> getNbBindings() == 2);
195195
void* buffers[2];
196-
196+
197197
// In order to bind the buffers, we need to know the names of the input and output tensors.
198198
// Note that indices are guaranteed to be less than IEngine::getNbBindings()
199199
const int inputIndex = mEngine->getBindingIndex(mParams.inputTensorName);
200200
const int outputIndex = mEngine->getBindingIndex(mParams.outputTensorName);
201-
201+
202202
// Create GPU buffers on device
203203
CUDA_CHECK(cudaMalloc(&buffers[inputIndex], batchSize * 3 * mParams.inputH * mParams.inputW * sizeof(float)));
204204
CUDA_CHECK(cudaMalloc(&buffers[outputIndex], batchSize * 1000 * sizeof(float)));
205-
205+
206206
// Create stream
207207
cudaStream_t stream;
208208
CUDA_CHECK(cudaStreamCreate(&stream));
209-
209+
210210
// DMA input batch data to device, infer on the batch asynchronously, and DMA output back to host
211211
CUDA_CHECK(cudaMemcpyAsync(buffers[inputIndex], input, batchSize * 3 * mParams.inputH * mParams.inputW * sizeof(float), cudaMemcpyHostToDevice, stream));
212212
mContext->enqueue(batchSize, buffers, stream, nullptr);
213213
CUDA_CHECK(cudaMemcpyAsync(output, buffers[outputIndex], batchSize * 1000 * sizeof(float), cudaMemcpyDeviceToHost, stream));
214214
cudaStreamSynchronize(stream);
215-
215+
216216
// Release stream and buffers
217217
cudaStreamDestroy(stream);
218218
CUDA_CHECK(cudaFree(buffers[inputIndex]));
@@ -232,4 +232,5 @@ namespace trtx {
232232

233233
return true;
234234
}
235-
}
235+
}
236+

lenet/lenet.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ int main(int argc, char** argv)
221221
APIToModel(1, &modelStream);
222222
assert(modelStream != nullptr);
223223

224-
std::ofstream p("lenet5.engine");
224+
std::ofstream p("lenet5.engine", std::ios::binary);
225225
if (!p)
226226
{
227227
std::cerr << "could not open plan output file" << std::endl;

0 commit comments

Comments
 (0)