forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pytorch#709 from colesbury/pinned_memory
Fix bug where pinned memory event could be recorded on incorrect device
- Loading branch information
Showing
7 changed files
with
132 additions
and
94 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 was deleted.
Oops, something went wrong.
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,60 @@ | ||
#include "THCStream.h" | ||
|
||
#include <mutex> | ||
#include <cuda_runtime_api.h> | ||
#include "THAtomic.h" | ||
|
||
#define MAX_DEVICES 256 | ||
static THCStream default_streams[MAX_DEVICES]; | ||
|
||
static void initialize_default_streams() | ||
{ | ||
for (int i = 0; i < MAX_DEVICES; i++) { | ||
default_streams[i].device = i; | ||
} | ||
} | ||
|
||
THCStream* THCStream_new(int flags) | ||
{ | ||
THCStream* self = (THCStream*) malloc(sizeof(THCStream)); | ||
self->refcount = 1; | ||
THCudaCheck(cudaGetDevice(&self->device)); | ||
THCudaCheck(cudaStreamCreateWithFlags(&self->stream, flags)); | ||
return self; | ||
} | ||
|
||
THC_API THCStream* THCStream_defaultStream(int device) | ||
{ | ||
// default streams aren't refcounted | ||
THAssert(device >= 0 && device < MAX_DEVICES); | ||
std::once_flag once; | ||
std::call_once(once, &initialize_default_streams); | ||
return &default_streams[device]; | ||
} | ||
|
||
THCStream* THCStream_newWithPriority(int flags, int priority) | ||
{ | ||
THCStream* self = (THCStream*) malloc(sizeof(THCStream)); | ||
self->refcount = 1; | ||
THCudaCheck(cudaGetDevice(&self->device)); | ||
THCudaCheck(cudaStreamCreateWithPriority(&self->stream, flags, priority)); | ||
return self; | ||
} | ||
|
||
void THCStream_free(THCStream* self) | ||
{ | ||
if (!self || !self->stream) { | ||
return; | ||
} | ||
if (THAtomicDecrementRef(&self->refcount)) { | ||
THCudaCheckWarn(cudaStreamDestroy(self->stream)); | ||
free(self); | ||
} | ||
} | ||
|
||
void THCStream_retain(THCStream* self) | ||
{ | ||
if (self->stream) { | ||
THAtomicIncrementRef(&self->refcount); | ||
} | ||
} |
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