Skip to content

Commit c555cd8

Browse files
committed
missing fixed allocator files
1 parent 5e078bb commit c555cd8

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

CPUFixedAllocator.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include "TH/TH.h"
4+
5+
// This file creates a fake allocator that just throws exceptions if
6+
// it is actually used.
7+
8+
// state passed to the allocator is the std::function<void(void*)> called
9+
// when the blob is release by ATen
10+
11+
namespace at {
12+
13+
static cpu_fixed_malloc(void *, ptrdiff_t) {
14+
runtime_error("attempting to resize a tensor view of an external blob");
15+
}
16+
17+
static cpu_fixed_realloc(void *, void*, ptrdiff_t) {
18+
runtime_error("attempting to resize a tensor view of an external blob");
19+
}
20+
21+
static cpu_fixed_free(void * state, void * allocation) {
22+
auto on_release = static_cast<std::function<void(void*)>*>(state);
23+
(*on_release)(allocation);
24+
delete on_release;
25+
}
26+
27+
static THAllocator CPU_fixed_allocator =
28+
{ cpu_fixed_malloc, cpu_fixed_realloc, cpu_fixed_free };
29+
30+
}

CUDAFixedAllocator.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
3+
#include "THC/THC.h"
4+
5+
// This file creates a fake allocator that just throws exceptions if
6+
// it is actually used.
7+
8+
// state passed to the allocator is the std::function<void(void*)> called
9+
// when the blob is release by ATen
10+
11+
namespace at {
12+
13+
static cuda_fixed_malloc(void *, void**, size_t, cudaStream_t) {
14+
runtime_error("attempting to resize a tensor view of an external blob");
15+
}
16+
17+
static cpu_fixed_realloc(void*, void**, size_t, size_t, cudaStream_t) {
18+
runtime_error("attempting to resize a tensor view of an external blob");
19+
}
20+
21+
static cuda_fixed_free(void * state, void * allocation) {
22+
auto on_release = static_cast<std::function<void(void*)>*>(state);
23+
(*on_release)(allocation);
24+
delete on_release;
25+
}
26+
27+
static cuda_fixed_emptyCache(void*) {
28+
runtime_error("?? attempting to resize a tensor view of an external blob");
29+
}
30+
31+
static cuda_fixed_cacheInfo(void*, int, size_t*, size_t*) {
32+
runtime_error("?? attempting to resize a tensor view of an external blob");
33+
}
34+
35+
36+
static THCDeviceAllocator CUDA_fixed_allocator = {
37+
cuda_fixed_malloc, cuda_fixed_realloc, cuda_fixed_free, cuda_fixed_emptyCache,
38+
cuda_fixed_cacheInfo
39+
};
40+
41+
42+
}

0 commit comments

Comments
 (0)