-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathbitgenerator.cc
More file actions
105 lines (85 loc) · 3.03 KB
/
bitgenerator.cc
File metadata and controls
105 lines (85 loc) · 3.03 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* Copyright 2021-2022 NVIDIA Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// MacOS host variant:
//
#if defined(__APPLE__) && defined(__MACH__)
#define USE_STL_RANDOM_ENGINE_
#endif
#include "cunumeric/random/bitgenerator.h"
#include "cunumeric/random/bitgenerator_template.inl"
#include "cunumeric/random/bitgenerator_util.h"
#include "cunumeric/random/rnd_types.h"
#include "cunumeric/random/randutil/randutil.h"
#include "cunumeric/random/bitgenerator_curand.inl"
namespace cunumeric {
using namespace legate;
static Logger log_curand("cunumeric.random");
Logger& randutil_log() { return log_curand; }
#ifdef USE_STL_RANDOM_ENGINE_
void randutil_check_status(rnd_status_t error, const char* file, int line)
{
if (error) {
randutil_log().fatal() << "Internal random engine failure with error " << (int)error
<< " in file " << file << " at line " << line;
assert(false);
}
}
#else
void randutil_check_curand(curandStatus_t error, const char* file, int line)
{
if (error != CURAND_STATUS_SUCCESS) {
randutil_log().fatal() << "Internal CURAND failure with error " << (int)error << " in file "
<< file << " at line " << line;
assert(false);
}
}
#endif
struct CPUGenerator : public CURANDGenerator {
CPUGenerator(BitGeneratorType gentype, uint64_t seed, uint64_t generatorId, uint32_t flags)
: CURANDGenerator(gentype, seed, generatorId)
{
CHECK_RND_ENGINE(::randutilCreateGeneratorHost(&gen_, type_, seed, generatorId, flags));
}
virtual ~CPUGenerator() { CHECK_RND_ENGINE(::randutilDestroyGenerator(gen_)); }
};
template <>
struct CURANDGeneratorBuilder<VariantKind::CPU> {
static CURANDGenerator* build(BitGeneratorType gentype,
uint64_t seed,
uint64_t generatorId,
uint32_t flags)
{
return new CPUGenerator(gentype, seed, generatorId, flags);
}
static void destroy(CURANDGenerator* cugenptr) { delete cugenptr; }
};
template <>
std::map<legate::Processor, std::unique_ptr<generator_map<VariantKind::CPU>>>
BitGeneratorImplBody<VariantKind::CPU>::m_generators = {};
template <>
std::mutex BitGeneratorImplBody<VariantKind::CPU>::lock_generators = {};
/*static*/ void BitGeneratorTask::cpu_variant(TaskContext& context)
{
bitgenerator_template<VariantKind::CPU>(context);
}
namespace // unnamed
{
static void __attribute__((constructor)) register_tasks(void)
{
BitGeneratorTask::register_variants();
}
} // namespace
} // namespace cunumeric