From 8f765c80ff20fcc4a819fdf3e87c680f589adeed Mon Sep 17 00:00:00 2001 From: raver119 Date: Thu, 23 Apr 2020 08:24:49 +0300 Subject: [PATCH] - do not use GetShortName approach for mmap on windows (#408) - additional test for long file names on windows Signed-off-by: raver119 --- libnd4j/include/helpers/mman.h | 6 ++--- .../workspace/SpecialWorkspaceTests.java | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/libnd4j/include/helpers/mman.h b/libnd4j/include/helpers/mman.h index 21f3fcceb..484832beb 100644 --- a/libnd4j/include/helpers/mman.h +++ b/libnd4j/include/helpers/mman.h @@ -145,8 +145,6 @@ void _mmap(Nd4jLong* result, size_t length, const char *fileName) { auto shortName = new TCHAR[sz]; GetShortPathName(fileName, shortName, sz); - delete[] shortName; - #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable: 4293) @@ -170,7 +168,9 @@ void _mmap(Nd4jLong* result, size_t length, const char *fileName) { #pragma warning(pop) #endif - h = CreateFile(shortName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + h = CreateFileA(fileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + + delete[] shortName; if (h == INVALID_HANDLE_VALUE) { errno = __map_mman_error(GetLastError(), EPERM); diff --git a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/workspace/SpecialWorkspaceTests.java b/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/workspace/SpecialWorkspaceTests.java index 02876fdbb..8613d60a2 100644 --- a/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/workspace/SpecialWorkspaceTests.java +++ b/nd4j/nd4j-backends/nd4j-tests/src/test/java/org/nd4j/linalg/workspace/SpecialWorkspaceTests.java @@ -357,6 +357,29 @@ public class SpecialWorkspaceTests extends BaseNd4jTest { } } + @Test + public void testMmapedWorkspace_Path_Limits_1() throws Exception { + if (!Nd4j.getEnvironment().isCPU()) + return; + + // getting very long file name + val builder = new StringBuilder("long_file_name_"); + for (int e = 0; e < 100; e++) + builder.append("9"); + + + val tmpFile = Files.createTempFile("some", builder.toString()); + val mmap = WorkspaceConfiguration.builder() + .initialSize(200 * 1024L * 1024L) // 200mbs + .tempFilePath(tmpFile.toAbsolutePath().toString()) + .policyLocation(LocationPolicy.MMAP) + .build(); + + try (val ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(mmap, "M2")) { + val x = Nd4j.rand(DataType.FLOAT, 1024); + } + } + @Override public char ordering() { return 'c';