Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
apex
Commits
bdac244e
Unverified
Commit
bdac244e
authored
Sep 30, 2021
by
X Wang
Committed by
GitHub
Sep 30, 2021
Browse files
use cuda caching allocator from pytorch (#1180)
parent
2a559c51
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
17 deletions
+14
-17
.gitignore
.gitignore
+2
-0
apex/contrib/csrc/groupbn/batch_norm.cu
apex/contrib/csrc/groupbn/batch_norm.cu
+6
-8
apex/contrib/csrc/groupbn/batch_norm_add_relu.cu
apex/contrib/csrc/groupbn/batch_norm_add_relu.cu
+6
-8
apex/contrib/csrc/xentropy/xentropy_kernel.cu
apex/contrib/csrc/xentropy/xentropy_kernel.cu
+0
-1
No files found.
.gitignore
View file @
bdac244e
...
...
@@ -4,3 +4,5 @@ build
docs/build
*~
__pycache__
*.so
.vscode
\ No newline at end of file
apex/contrib/csrc/groupbn/batch_norm.cu
View file @
bdac244e
#include <ATen/ATen.h>
#include <ATen/cuda/CUDAContext.h>
#include <THC/THCNumerics.cuh>
#include <c10/cuda/CUDACachingAllocator.h>
#include "THC/THC.h"
...
...
@@ -26,23 +27,20 @@ static size_t round_up_to_multiple(size_t x, int multiple) {
return
((
x
+
multiple
-
1
)
/
multiple
)
*
multiple
;
}
// TODO: Stop manually allocating CUDA memory; allocate an ATen byte
// tensor instead.
struct
Workspace
{
Workspace
(
size_t
size
)
:
size
(
size
),
data
(
NULL
)
{
data
=
THCudaMalloc
(
at
::
globalContext
().
lazyInitCUDA
(),
size
);
auto
&
allocator
=
*::
c10
::
cuda
::
CUDACachingAllocator
::
get
();
dataPtr
=
allocator
.
allocate
(
size
);
data
=
dataPtr
.
get
();
}
Workspace
(
const
Workspace
&
)
=
delete
;
Workspace
(
Workspace
&&
)
=
default
;
Workspace
&
operator
=
(
Workspace
&&
)
=
default
;
~
Workspace
()
{
if
(
data
)
{
THCudaFree
(
at
::
globalContext
().
lazyInitCUDA
(),
data
);
}
}
~
Workspace
()
=
default
;
size_t
size
;
void
*
data
;
c10
::
DataPtr
dataPtr
;
};
// Return {y}
...
...
apex/contrib/csrc/groupbn/batch_norm_add_relu.cu
View file @
bdac244e
#include <ATen/ATen.h>
#include <ATen/cuda/CUDAContext.h>
#include <THC/THCNumerics.cuh>
#include <c10/cuda/CUDACachingAllocator.h>
#include "THC/THC.h"
...
...
@@ -27,23 +28,20 @@ static size_t round_up_to_multiple(size_t x, int multiple) {
return
((
x
+
multiple
-
1
)
/
multiple
)
*
multiple
;
}
// TODO: Stop manually allocating CUDA memory; allocate an ATen byte
// tensor instead.
struct
Workspace
{
Workspace
(
size_t
size
)
:
size
(
size
),
data
(
NULL
)
{
data
=
THCudaMalloc
(
at
::
globalContext
().
lazyInitCUDA
(),
size
);
auto
&
allocator
=
*::
c10
::
cuda
::
CUDACachingAllocator
::
get
();
dataPtr
=
allocator
.
allocate
(
size
);
data
=
dataPtr
.
get
();
}
Workspace
(
const
Workspace
&
)
=
delete
;
Workspace
(
Workspace
&&
)
=
default
;
Workspace
&
operator
=
(
Workspace
&&
)
=
default
;
~
Workspace
()
{
if
(
data
)
{
THCudaFree
(
at
::
globalContext
().
lazyInitCUDA
(),
data
);
}
}
~
Workspace
()
=
default
;
size_t
size
;
void
*
data
;
c10
::
DataPtr
dataPtr
;
};
// Return {y}
...
...
apex/contrib/csrc/xentropy/xentropy_kernel.cu
View file @
bdac244e
...
...
@@ -78,7 +78,6 @@
#include <THC/THC.h>
#include <THC/THCGeneral.h>
#include <THC/THCThrustAllocator.cuh>
#include "type_shim.h"
#include "compat.h"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment