Skip to content

Commit 04b1e4d

Browse files
authored
tensor module windows support (#12934)
* tensor windows support * "fix ci" * "remove utils"
1 parent 77c0aeb commit 04b1e4d

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

paddle/fluid/framework/lod_tensor.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ limitations under the License. */
2525
#include "paddle/fluid/memory/memcpy.h"
2626
#include "paddle/fluid/memory/memory.h"
2727

28+
#if !defined(_WIN32)
2829
#include "paddle/fluid/recordio/scanner.h"
2930
#include "paddle/fluid/recordio/writer.h"
31+
#endif // _WIN32
3032

3133
namespace paddle {
3234
namespace framework {
@@ -300,6 +302,7 @@ void DeserializeFromStream(std::istream &is, LoDTensor *tensor,
300302
TensorFromStream(is, static_cast<Tensor *>(tensor), dev_ctx);
301303
}
302304

305+
#if !defined(_WIN32)
303306
void WriteToRecordIO(recordio::Writer *writer,
304307
const std::vector<LoDTensor> &tensor,
305308
const platform::DeviceContext &dev_ctx) {
@@ -329,7 +332,19 @@ bool ReadFromRecordIO(recordio::Scanner *scanner,
329332

330333
return true;
331334
}
332-
335+
#else
336+
class Writer {};
337+
class Scanner {};
338+
void WriteToRecordIO(recordio::Writer *writer,
339+
const std::vector<LoDTensor> &tensor,
340+
const platform::DeviceContext &dev_ctx) {}
341+
bool ReadFromRecordIO(recordio::Scanner *scanner,
342+
const platform::DeviceContext &dev_ctx,
343+
std::vector<LoDTensor> *result_ptr) {
344+
PADDLE_ENFORCE("windows didn't supported recordio!.");
345+
return true;
346+
}
347+
#endif // _WIN32
333348
std::vector<LoDTensor> LoDTensor::SplitLoDTensor(
334349
const std::vector<platform::Place> places) const {
335350
check_memory_size();

paddle/fluid/framework/lod_tensor_test.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ TEST(LoD, ConvertToOffsetBasedLoD) {
274274
EXPECT_EQ(offset_lod, expected);
275275
}
276276

277+
#if !defined(_WIN32)
277278
template <typename T>
278279
static void TestRecordIO() {
279280
LoDTensor tensor;
@@ -320,6 +321,7 @@ TEST(LoDTensor, RecordIO) {
320321
TestRecordIO<float>();
321322
TestRecordIO<double>();
322323
}
324+
#endif // !defined(_WIN32)
323325

324326
} // namespace framework
325327
} // namespace paddle

paddle/fluid/framework/rw_lock.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ limitations under the License. */
1414

1515
#pragma once
1616

17+
#if !defined(_WIN32)
1718
#include <pthread.h>
19+
#endif // !_WIN32
1820

1921
#include "paddle/fluid/platform/enforce.h"
2022

2123
namespace paddle {
2224
namespace framework {
2325

26+
#if !defined(_WIN32)
2427
struct RWLock {
2528
RWLock() { pthread_rwlock_init(&lock_, nullptr); }
2629

@@ -43,6 +46,15 @@ struct RWLock {
4346
private:
4447
pthread_rwlock_t lock_;
4548
};
49+
#else
50+
// https://stackoverflow.com/questions/7125250/making-pthread-rwlock-wrlock-recursive
51+
// In windows, rw_lock seems like a hack. Use empty object and do nothing.
52+
struct RWLock {
53+
void RDLock() {}
54+
void WRLock() {}
55+
void UNLock() {}
56+
};
57+
#endif
4658

4759
} // namespace framework
4860
} // namespace paddle

0 commit comments

Comments
 (0)