forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Back out "Back out "[pytorch][PR] Move thnvrtc and DynamicLibrary to …
…ATen"" (pytorch#22794) Summary: Original commit changeset: 227df3b85316 Pull Request resolved: pytorch#22794 ghstack-source-id: 86400904 Differential Revision: D16222777 fbshipit-source-id: 0b198ac59e640df0b8204b4ed30f8e822c15fd9a
- Loading branch information
1 parent
317cf7c
commit 535c554
Showing
29 changed files
with
375 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <c10/util/Exception.h> | ||
#include <ATen/DynamicLibrary.h> | ||
#include <ATen/Utils.h> | ||
|
||
#ifndef _WIN32 | ||
#include <dlfcn.h> | ||
#include <libgen.h> | ||
#else | ||
#include <Windows.h> | ||
#endif | ||
|
||
namespace at { | ||
|
||
|
||
#ifndef _WIN32 | ||
|
||
// Unix | ||
|
||
static void* checkDL(void* x) { | ||
if (!x) { | ||
AT_ERROR("Error in dlopen or dlsym: ", dlerror()); | ||
} | ||
|
||
return x; | ||
} | ||
DynamicLibrary::DynamicLibrary(const char* name) { | ||
// NOLINTNEXTLINE(hicpp-signed-bitwise) | ||
handle = checkDL(dlopen(name, RTLD_LOCAL | RTLD_NOW)); | ||
} | ||
|
||
void* DynamicLibrary::sym(const char* name) { | ||
AT_ASSERT(handle); | ||
return checkDL(dlsym(handle, name)); | ||
} | ||
|
||
DynamicLibrary::~DynamicLibrary() { | ||
if (!handle) | ||
return; | ||
dlclose(handle); | ||
} | ||
|
||
#else | ||
|
||
// Windows | ||
|
||
DynamicLibrary::DynamicLibrary(const char* name) { | ||
// NOLINTNEXTLINE(hicpp-signed-bitwise) | ||
HMODULE theModule = LoadLibraryA(name); | ||
if (theModule) { | ||
handle = theModule; | ||
} else { | ||
AT_ERROR("error in LoadLibraryA"); | ||
} | ||
} | ||
|
||
void* DynamicLibrary::sym(const char* name) { | ||
AT_ASSERT(handle); | ||
FARPROC procAddress = GetProcAddress((HMODULE)handle, name); | ||
if (!procAddress) { | ||
AT_ERROR("error in GetProcAddress"); | ||
} | ||
return (void*)procAddress; | ||
} | ||
|
||
DynamicLibrary::~DynamicLibrary() { | ||
if (!handle) { | ||
return; | ||
} | ||
FreeLibrary((HMODULE)handle); | ||
} | ||
|
||
#endif | ||
|
||
} // namespace at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <c10/macros/Export.h> | ||
#include <ATen/Utils.h> | ||
|
||
namespace at { | ||
|
||
struct DynamicLibrary { | ||
AT_DISALLOW_COPY_AND_ASSIGN(DynamicLibrary); | ||
|
||
CAFFE2_API DynamicLibrary(const char* name); | ||
|
||
CAFFE2_API void* sym(const char* name); | ||
|
||
CAFFE2_API ~DynamicLibrary(); | ||
|
||
private: | ||
void* handle = nullptr; | ||
}; | ||
|
||
} // namespace at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <ATen/cuda/nvrtc_stub/ATenNVRTC.h> | ||
#include <iostream> | ||
|
||
namespace at { namespace cuda { | ||
|
||
NVRTC* load_nvrtc() { | ||
auto self = new NVRTC(); | ||
#define CREATE_ASSIGN(name) self->name = name; | ||
AT_FORALL_NVRTC(CREATE_ASSIGN) | ||
return self; | ||
} | ||
|
||
}} // at::cuda |
Oops, something went wrong.