9 #include "columns/RandomSeed.hpp" 10 #include "utils/PVLog.hpp" 21 Random::Random(
int count) {
23 initializeFromCount((
unsigned int)count);
33 Random::Random(
const PVLayerLoc *locptr,
bool isExtended) {
35 initializeFromLoc(locptr, isExtended);
38 int Random::initialize_base() {
return PV_SUCCESS; }
41 int Random::initializeFromLoc(
const PVLayerLoc *locptr,
bool isExtended) {
42 int status = PV_SUCCESS;
54 int nxExt = locptr->nx + halo.lt + halo.rt;
55 int nyExt = locptr->ny + halo.up + halo.dn;
57 int nbatch = locptr->nbatch;
58 int rngCount = nxExt * nyExt * nf * nbatch;
60 int nxGlobalExt = locptr->nxGlobal + halo.lt + halo.rt;
61 int nyGlobalExt = locptr->nyGlobal + halo.up + halo.dn;
62 int nbatchGlobal = locptr->nbatchGlobal;
64 rngArray.resize(rngCount);
65 if (status == PV_SUCCESS) {
66 int numTotalSeeds = nxGlobalExt * nyGlobalExt * nf * nbatchGlobal;
67 unsigned int seedBase = RandomSeed::instance()->allocate(numTotalSeeds);
68 int sb = nxExt * nyExt * nf;
70 int sbGlobal = nxGlobalExt * nyGlobalExt * nf;
71 int syGlobal = nxGlobalExt * nf;
75 for (
int kb = 0; kb < nbatch; kb++) {
76 for (
int ky = 0; ky < nyExt; ky++) {
78 int localExtStart = kb * sb + ky * sy;
81 (kb + locptr->kb0) * sbGlobal + (ky + locptr->ky0) * syGlobal + locptr->kx0;
82 size_t count = nxExt * nf;
83 cl_random_init(&(rngArray[localExtStart]), count, seedBase + globalExtStart);
90 int Random::initializeFromCount(
int count) {
91 int status = PV_SUCCESS;
92 rngArray.resize(count);
93 if (status == PV_SUCCESS) {
94 unsigned int seedBase = RandomSeed::instance()->allocate(count);
95 cl_random_init(rngArray.data(), (size_t)count, seedBase);
100 float Random::uniformRandom(
int localIndex) {
101 rngArray[localIndex] = cl_random_get(rngArray[localIndex]);
102 return rngArray[localIndex].s0 / (float)randomUIntMax();
105 unsigned int Random::randomUInt(
int localIndex) {
106 rngArray[localIndex] = cl_random_get(rngArray[localIndex]);
107 return rngArray[localIndex].s0;