python-torch: add shm_{open,unlink} to ATen
This commit is contained in:
parent
6101f222a0
commit
a566982ebc
|
@ -66,3 +66,77 @@ diff -uNr pytorch-v1.12.1/torch/lib/libshm/manager.cpp pytorch-v1.12.1.mod/torch
|
|||
+
|
||||
struct ClientSession {
|
||||
ClientSession(ManagerSocket s) : socket(std::move(s)), pid(0) {}
|
||||
|
||||
diff -uNr a/aten/src/ATen/MapAllocator.cpp b/aten/src/ATen/MapAllocator.cpp
|
||||
--- a/aten/src/ATen/MapAllocator.cpp 2023-04-28 19:28:54.000000000 +0900
|
||||
+++ b/aten/src/ATen/MapAllocator.cpp 2023-04-28 19:30:12.000000000 +0900
|
||||
@@ -29,6 +29,69 @@
|
||||
#include <c10/util/win32-headers.h>
|
||||
#endif
|
||||
|
||||
+#define HAVE_SHM_OPEN 1
|
||||
+#define HAVE_SHM_UNLINK 1
|
||||
+
|
||||
+static int shm_unlink(const char *name) {
|
||||
+ size_t namelen;
|
||||
+ char *fname;
|
||||
+
|
||||
+ /* Construct the filename. */
|
||||
+ while (name[0] == '/') ++name;
|
||||
+
|
||||
+ if (name[0] == '\0') {
|
||||
+ /* The name "/" is not supported. */
|
||||
+ errno = EINVAL;
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ namelen = strlen(name);
|
||||
+ fname = (char *) alloca(sizeof("@TERMUX_PREFIX@/tmp/") - 1 + namelen + 1);
|
||||
+ memcpy(fname, "@TERMUX_PREFIX@/tmp/", sizeof("@TERMUX_PREFIX@/tmp/") - 1);
|
||||
+ memcpy(fname + sizeof("@TERMUX_PREFIX@/tmp/") - 1, name, namelen + 1);
|
||||
+
|
||||
+ return unlink(fname);
|
||||
+}
|
||||
+
|
||||
+static int shm_open(const char *name, int oflag, mode_t mode) {
|
||||
+ size_t namelen;
|
||||
+ char *fname;
|
||||
+ int fd;
|
||||
+
|
||||
+ /* Construct the filename. */
|
||||
+ while (name[0] == '/') ++name;
|
||||
+
|
||||
+ if (name[0] == '\0') {
|
||||
+ /* The name "/" is not supported. */
|
||||
+ errno = EINVAL;
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ namelen = strlen(name);
|
||||
+ fname = (char *) alloca(sizeof("@TERMUX_PREFIX@/tmp/") - 1 + namelen + 1);
|
||||
+ memcpy(fname, "@TERMUX_PREFIX@/tmp/", sizeof("@TERMUX_PREFIX@/tmp/") - 1);
|
||||
+ memcpy(fname + sizeof("@TERMUX_PREFIX@/tmp/") - 1, name, namelen + 1);
|
||||
+
|
||||
+ fd = open(fname, oflag, mode);
|
||||
+ if (fd != -1) {
|
||||
+ /* We got a descriptor. Now set the FD_CLOEXEC bit. */
|
||||
+ int flags = fcntl(fd, F_GETFD, 0);
|
||||
+ flags |= FD_CLOEXEC;
|
||||
+ flags = fcntl(fd, F_SETFD, flags);
|
||||
+
|
||||
+ if (flags == -1) {
|
||||
+ /* Something went wrong. We cannot return the descriptor. */
|
||||
+ int save_errno = errno;
|
||||
+ close(fd);
|
||||
+ fd = -1;
|
||||
+ errno = save_errno;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return fd;
|
||||
+}
|
||||
+
|
||||
+
|
||||
namespace at {
|
||||
|
||||
static constexpr int64_t map_alloc_alignment = 64;
|
||||
|
|
|
@ -3,7 +3,7 @@ TERMUX_PKG_DESCRIPTION="Tensors and Dynamic neural networks in Python"
|
|||
TERMUX_PKG_LICENSE="BSD 3-Clause"
|
||||
TERMUX_PKG_MAINTAINER="@termux"
|
||||
TERMUX_PKG_VERSION=2.0.0
|
||||
TERMUX_PKG_REVISION=1
|
||||
TERMUX_PKG_REVISION=2
|
||||
TERMUX_PKG_SRCURL=git+https://github.com/pytorch/pytorch
|
||||
TERMUX_PKG_DEPENDS="ffmpeg, libc++, libopenblas, libprotobuf, libzmq, opencv, python, python-numpy, python-pip"
|
||||
TERMUX_PKG_HOSTBUILD=true
|
||||
|
|
Loading…
Reference in New Issue