Assuming the data is actually binary and not characters, some of it can easily have value 32
or 10
or some such. You're reading the file using "%c "
, which means such values (ASCII code of space and linefeed, respectively) will happily be skipped as whitespace.
Seeing as you've tagged this with C++, you could simply do I/O the C++ way:
cudaMemcpy( data, input, memsize,cudaMemcpyDeviceToHost);
{
std::ofstream f(filename, std::ios::binary);
f.write(data, memsize);
}
free(data);
// And
{
std::ifstream f(filename, std::ios::binary);
f.read(data, memsize);
}
cudaMemcpy( input, data, memsize,cudaMemcpyHostToDevice);
Of course, you could also use std::vector<char>
instead of char*
and get rid of all the manual allocation and deallocation. The code would then simplify:
size_t memsize = frameWidth * frameHeight;
std::vector<char> data(memsize);
cudaMemcpy(&data[0], input, memsize,cudaMemcpyDeviceToHost);
{
std::ofstream f(filename, std::ios::binary);
f.write(&data[00, memsize);
}
data.clear();
// Now read back
data.resize(memsize);
{
std::ifstream f(filename, std::ios::binary);
f.read(&data[0], memsize);
}
cudaMemcpy( input, data, memsize,cudaMemcpyHostToDevice);
data.clear(); // optionally