forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPUGenerator.cpp
49 lines (37 loc) · 1.01 KB
/
CPUGenerator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <ATen/CPUGenerator.h>
#define const_generator_cast(generator) \
dynamic_cast<const CPUGenerator&>(generator)
namespace at {
CPUGenerator::CPUGenerator(Context * context_)
: context(context_), generator(THGenerator_new())
{}
CPUGenerator::~CPUGenerator() {
if (generator)
THGenerator_free(generator);
}
CPUGenerator& CPUGenerator::copy(const Generator& from) {
THGenerator_copy(generator, const_generator_cast(from).generator);
return *this;
}
CPUGenerator& CPUGenerator::free() {
THGenerator_free(generator);
return *this;
}
uint64_t CPUGenerator::seed() {
return THRandom_seed(generator);
}
uint64_t CPUGenerator::initialSeed() {
return THRandom_initialSeed(generator);
}
CPUGenerator& CPUGenerator::manualSeed(uint64_t seed) {
THRandom_manualSeed(generator, seed);
return *this;
}
CPUGenerator& CPUGenerator::manualSeedAll(uint64_t seed) {
// There's only one CPU generator
return manualSeed(seed);
}
void * CPUGenerator::unsafeGetTH() {
return generator;
}
} // namespace at