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.
Move thnvrtc and DynamicLibrary to ATen (pytorch#22362)
Summary: Having the NVRTC stub in ATen is necessary to call driver APIs in ATen. This is currently blocking pytorch#22229. `DynamicLibrary` is also moved as it is used in the stub code, and seems general enough. Pull Request resolved: pytorch#22362 Differential Revision: D16131787 Pulled By: ezyang fbshipit-source-id: add2ee8a8865229578aa00001a00d5a6671e0e73
- Loading branch information
1 parent
74883d4
commit 31d821e
Showing
28 changed files
with
356 additions
and
270 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.