本文整理汇总了C++中sys::ComputeSystem类的典型用法代码示例。如果您正苦于以下问题:C++ ComputeSystem类的具体用法?C++ ComputeSystem怎么用?C++ ComputeSystem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ComputeSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
DoubleBuffer2D neo::createDoubleBuffer2D(sys::ComputeSystem &cs, cl_int2 size) {
DoubleBuffer2D db;
db[_front] = cl::Image2D(cs.getContext(), CL_MEM_READ_WRITE, cl::ImageFormat(CL_R, CL_FLOAT), size.x, size.y);
db[_back] = cl::Image2D(cs.getContext(), CL_MEM_READ_WRITE, cl::ImageFormat(CL_R, CL_FLOAT), size.x, size.y);
return db;
}
示例2: activate
void Predictor::activate(sys::ComputeSystem &cs, const std::vector<cl::Image2D> &visibleStates, NonlinearityType nonlinearityType, bool bufferSwap) {
// Start by clearing summation buffer
{
cl_float4 zeroColor = { 0.0f, 0.0f, 0.0f, 0.0f };
cl::array<cl::size_type, 3> zeroOrigin = { 0, 0, 0 };
cl::array<cl::size_type, 3> hiddenRegion = { _hiddenSize.x, _hiddenSize.y, 1 };
cs.getQueue().enqueueFillImage(_hiddenSummationTemp[_back], zeroColor, zeroOrigin, hiddenRegion);
}
for (int vli = 0; vli < _visibleLayers.size(); vli++) {
VisibleLayer &vl = _visibleLayers[vli];
VisibleLayerDesc &vld = _visibleLayerDescs[vli];
int argIndex = 0;
_activateKernel.setArg(argIndex++, visibleStates[vli]);
_activateKernel.setArg(argIndex++, _hiddenSummationTemp[_back]);
_activateKernel.setArg(argIndex++, _hiddenSummationTemp[_front]);
_activateKernel.setArg(argIndex++, vl._weights[_back]);
_activateKernel.setArg(argIndex++, vld._size);
_activateKernel.setArg(argIndex++, vl._hiddenToVisible);
_activateKernel.setArg(argIndex++, vld._radius);
cs.getQueue().enqueueNDRangeKernel(_activateKernel, cl::NullRange, cl::NDRange(_hiddenSize.x, _hiddenSize.y));
// Swap buffers
std::swap(_hiddenSummationTemp[_front], _hiddenSummationTemp[_back]);
}
if (nonlinearityType == _binary) {
int argIndex = 0;
_solveHiddenBinaryKernel.setArg(argIndex++, _hiddenSummationTemp[_back]);
_solveHiddenBinaryKernel.setArg(argIndex++, _hiddenStates[_front]);
cs.getQueue().enqueueNDRangeKernel(_solveHiddenBinaryKernel, cl::NullRange, cl::NDRange(_hiddenSize.x, _hiddenSize.y));
}
else if (nonlinearityType == _tanH) {
int argIndex = 0;
_solveHiddenTanHKernel.setArg(argIndex++, _hiddenSummationTemp[_back]);
_solveHiddenTanHKernel.setArg(argIndex++, _hiddenStates[_front]);
cs.getQueue().enqueueNDRangeKernel(_solveHiddenTanHKernel, cl::NullRange, cl::NDRange(_hiddenSize.x, _hiddenSize.y));
}
else
cs.getQueue().enqueueCopyImage(_hiddenSummationTemp[_back], _hiddenStates[_front], { 0, 0, 0 }, { 0, 0, 0 }, { static_cast<cl::size_type>(_hiddenSize.x), static_cast<cl::size_type>(_hiddenSize.y), 1 });
// Swap hidden state buffers
std::swap(_hiddenStates[_front], _hiddenStates[_back]);
}
示例3: activate
void PredictorSwarm::activate(sys::ComputeSystem &cs, const cl::Image2D &targets, const std::vector<cl::Image2D> &visibleStates, const std::vector<cl::Image2D> &visibleStatesPrev, float activeRatio, int inhibitionRadius, float noise, std::mt19937 &rng) {
// Start by clearing summation buffer
{
cl_float4 zeroColor = { 0.0f, 0.0f, 0.0f, 0.0f };
cl::array<cl::size_type, 3> zeroOrigin = { 0, 0, 0 };
cl::array<cl::size_type, 3> hiddenRegion = { _hiddenSize.x, _hiddenSize.y, 1 };
//cs.getQueue().enqueueCopyImage(_hiddenBiases[_back], _hiddenSummationTemp[_back], zeroOrigin, zeroOrigin, hiddenRegion);
cs.getQueue().enqueueFillImage(_hiddenSummationTemp[_back], cl_float4{ 0.0f, 0.0f, 0.0f, 0.0f }, zeroOrigin, hiddenRegion);
}
for (int vli = 0; vli < _visibleLayers.size(); vli++) {
VisibleLayer &vl = _visibleLayers[vli];
VisibleLayerDesc &vld = _visibleLayerDescs[vli];
int argIndex = 0;
_activateKernel.setArg(argIndex++, visibleStates[vli]);
_activateKernel.setArg(argIndex++, _hiddenSummationTemp[_back]);
_activateKernel.setArg(argIndex++, _hiddenSummationTemp[_front]);
_activateKernel.setArg(argIndex++, vl._weights[_back]);
_activateKernel.setArg(argIndex++, vld._size);
_activateKernel.setArg(argIndex++, vl._hiddenToVisible);
_activateKernel.setArg(argIndex++, vld._radius);
cs.getQueue().enqueueNDRangeKernel(_activateKernel, cl::NullRange, cl::NDRange(_hiddenSize.x, _hiddenSize.y));
// Swap buffers
std::swap(_hiddenSummationTemp[_front], _hiddenSummationTemp[_back]);
}
{
std::uniform_int_distribution<int> seedDist(0, 999);
cl_uint2 seed = { seedDist(rng), seedDist(rng) };
int argIndex = 0;
_solveHiddenKernel.setArg(argIndex++, _hiddenSummationTemp[_back]);
_solveHiddenKernel.setArg(argIndex++, _hiddenStates[_front]);
_solveHiddenKernel.setArg(argIndex++, _hiddenActivations[_front]);
_solveHiddenKernel.setArg(argIndex++, _hiddenSize);
_solveHiddenKernel.setArg(argIndex++, inhibitionRadius);
_solveHiddenKernel.setArg(argIndex++, activeRatio);
cs.getQueue().enqueueNDRangeKernel(_solveHiddenKernel, cl::NullRange, cl::NDRange(_hiddenSize.x, _hiddenSize.y));
}
// Swap hidden state buffers
std::swap(_hiddenStates[_front], _hiddenStates[_back]);
std::swap(_hiddenActivations[_front], _hiddenActivations[_back]);
}
示例4: writeToStream
void Predictor::writeToStream(sys::ComputeSystem &cs, std::ostream &os) const {
abort(); // Not yet working
os << _hiddenSize.x << " " << _hiddenSize.y << std::endl;
{
std::vector<cl_float> hiddenStates(_hiddenSize.x * _hiddenSize.y);
cs.getQueue().enqueueReadImage(_hiddenStates[_back], CL_TRUE, { 0, 0, 0 }, { static_cast<cl::size_type>(_hiddenSize.x), static_cast<cl::size_type>(_hiddenSize.y), 1 }, 0, 0, hiddenStates.data());
for (int si = 0; si < hiddenStates.size(); si++)
os << hiddenStates[si] << " ";
os << std::endl;
}
// Layer information
os << _visibleLayers.size() << std::endl;
for (int vli = 0; vli < _visibleLayers.size(); vli++) {
const VisibleLayer &vl = _visibleLayers[vli];
const VisibleLayerDesc &vld = _visibleLayerDescs[vli];
// Desc
os << vld._size.x << " " << vld._size.y << " " << vld._radius << std::endl;
// Layer
int weightDiam = vld._radius * 2 + 1;
int numWeights = weightDiam * weightDiam;
cl_int3 weightsSize = cl_int3{ _hiddenSize.x, _hiddenSize.y, numWeights };
int totalNumWeights = weightsSize.x * weightsSize.y * weightsSize.z;
{
std::vector<cl_float> weights(totalNumWeights);
cs.getQueue().enqueueReadImage(vl._weights[_back], CL_TRUE, { 0, 0, 0 }, { static_cast<cl::size_type>(weightsSize.x), static_cast<cl::size_type>(weightsSize.y), static_cast<cl::size_type>(weightsSize.z) }, 0, 0, weights.data());
for (int wi = 0; wi < weights.size(); wi++)
os << weights[wi] << " ";
}
os << std::endl;
os << vl._hiddenToVisible.x << " " << vl._hiddenToVisible.y << " " << vl._visibleToHidden.x << " " << vl._visibleToHidden.y << " " << vl._reverseRadii.x << " " << vl._reverseRadii.y << std::endl;
}
}
示例5: learn
void Predictor::learn(sys::ComputeSystem &cs, float tdError, const cl::Image2D &targets, std::vector<cl::Image2D> &visibleStatesPrev, float weightAlpha, float weightLambda) {
// Learn weights
for (int vli = 0; vli < _visibleLayers.size(); vli++) {
VisibleLayer &vl = _visibleLayers[vli];
VisibleLayerDesc &vld = _visibleLayerDescs[vli];
int argIndex = 0;
_learnWeightsTracesKernel.setArg(argIndex++, visibleStatesPrev[vli]);
_learnWeightsTracesKernel.setArg(argIndex++, targets);
_learnWeightsTracesKernel.setArg(argIndex++, _hiddenStates[_front]);
_learnWeightsTracesKernel.setArg(argIndex++, vl._weights[_back]);
_learnWeightsTracesKernel.setArg(argIndex++, vl._weights[_front]);
_learnWeightsTracesKernel.setArg(argIndex++, vld._size);
_learnWeightsTracesKernel.setArg(argIndex++, vl._hiddenToVisible);
_learnWeightsTracesKernel.setArg(argIndex++, vld._radius);
_learnWeightsTracesKernel.setArg(argIndex++, weightAlpha);
_learnWeightsTracesKernel.setArg(argIndex++, weightLambda);
_learnWeightsTracesKernel.setArg(argIndex++, tdError);
cs.getQueue().enqueueNDRangeKernel(_learnWeightsTracesKernel, cl::NullRange, cl::NDRange(_hiddenSize.x, _hiddenSize.y));
std::swap(vl._weights[_front], vl._weights[_back]);
}
}
示例6: learnPrediction
void HEInet::learnPrediction(sys::ComputeSystem &cs, const cl::Image2D &inputImage, float alpha) {
cl_float2 eFeedForwardDimsToEDims = { static_cast<float>(_eiLayers.front().getConfig()._eWidth + 1) / static_cast<float>(_eiLayers.front().getConfig()._eFeedForwardWidth + 1), static_cast<float>(_eiLayers.front().getConfig()._eHeight + 1) / static_cast<float>(_eiLayers.front().getConfig()._eFeedForwardHeight + 1) };
cl_float2 eFeedForwardDimsToIDims = { static_cast<float>(_eiLayers.front().getConfig()._iWidth + 1) / static_cast<float>(_eiLayers.front().getConfig()._eFeedForwardWidth + 1), static_cast<float>(_eiLayers.front().getConfig()._iHeight + 1) / static_cast<float>(_eiLayers.front().getConfig()._eFeedForwardHeight + 1) };
cl_int2 eDims = { _eiLayers.front().getConfig()._eWidth, _eiLayers.front().getConfig()._eHeight };
cl_int2 iDims = { _eiLayers.front().getConfig()._iWidth, _eiLayers.front().getConfig()._iHeight };
int index = 0;
_kernels->_predictionLearnKernel.setArg(index++, _eSpikeSumsIterPrev);
_kernels->_predictionLearnKernel.setArg(index++, _iSpikeSumsIterPrev);
_kernels->_predictionLearnKernel.setArg(index++, inputImage);
_kernels->_predictionLearnKernel.setArg(index++, _predictionPrev);
_kernels->_predictionLearnKernel.setArg(index++, _predictionFromEWeights._weightsPrev);
_kernels->_predictionLearnKernel.setArg(index++, _predictionFromIWeights._weightsPrev);
_kernels->_predictionLearnKernel.setArg(index++, _predictionFromEWeights._weights);
_kernels->_predictionLearnKernel.setArg(index++, _predictionFromIWeights._weights);
_kernels->_predictionLearnKernel.setArg(index++, eFeedForwardDimsToEDims);
_kernels->_predictionLearnKernel.setArg(index++, eFeedForwardDimsToIDims);
_kernels->_predictionLearnKernel.setArg(index++, eDims);
_kernels->_predictionLearnKernel.setArg(index++, iDims);
_kernels->_predictionLearnKernel.setArg(index++, _predictionRadiusFromE);
_kernels->_predictionLearnKernel.setArg(index++, _predictionRadiusFromI);
_kernels->_predictionLearnKernel.setArg(index++, alpha);
cs.getQueue().enqueueNDRangeKernel(_kernels->_predictionLearnKernel, cl::NullRange, cl::NDRange(_eiLayers.front().getConfig()._eFeedForwardWidth, _eiLayers.front().getConfig()._eFeedForwardHeight));
}
示例7: update
void HEInet::update(sys::ComputeSystem &cs, const cl::Image2D &inputFrequencyImage, const cl::Image2D &zeroImage, float eta, float shDecay, float saDecay) {
// Update input spikes
int index = 0;
_kernels->_updateInputSpikesKernel.setArg(index++, inputFrequencyImage);
_kernels->_updateInputSpikesKernel.setArg(index++, _inputSpikeTimersPrev);
_kernels->_updateInputSpikesKernel.setArg(index++, _inputSpikesHistoryPrev);
_kernels->_updateInputSpikesKernel.setArg(index++, _inputSpikeTimers);
_kernels->_updateInputSpikesKernel.setArg(index++, _inputSpikes);
_kernels->_updateInputSpikesKernel.setArg(index++, _inputSpikesHistory);
_kernels->_updateInputSpikesKernel.setArg(index++, shDecay);
cs.getQueue().enqueueNDRangeKernel(_kernels->_updateInputSpikesKernel, cl::NullRange, cl::NDRange(_eiLayers.front().getConfig()._eFeedForwardWidth, _eiLayers.front().getConfig()._eFeedForwardHeight));
const cl::Image2D* pLayerInput = &_inputSpikesPrev;
// Feed forward
for (int li = 0; li < _eiLayers.size(); li++) {
_eiLayers[li].eActivate(cs, *pLayerInput, eta, shDecay, saDecay);
pLayerInput = &_eiLayers[li]._eLayer._statesPrev;
}
pLayerInput = &zeroImage;
// Feed back
for (int li = _eiLayers.size() - 1; li >= 0; li--) {
_eiLayers[li].iActivate(cs, *pLayerInput, eta, shDecay, saDecay);
pLayerInput = &_eiLayers[li]._iLayer._statesPrev;
}
}
示例8: learn
void PredictorSwarm::learn(sys::ComputeSystem &cs, float reward, float gamma, const cl::Image2D &targets, std::vector<cl::Image2D> &visibleStatesPrev, cl_float2 weightAlpha, cl_float2 weightLambda, cl_float biasAlpha, cl_float activeRatio, float noise) {
// Learn weights
for (int vli = 0; vli < _visibleLayers.size(); vli++) {
VisibleLayer &vl = _visibleLayers[vli];
VisibleLayerDesc &vld = _visibleLayerDescs[vli];
int argIndex = 0;
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, visibleStatesPrev[vli]);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, targets);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, _hiddenStates[_back]);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, _hiddenActivations[_front]);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, _hiddenStates[_front]);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, vl._weights[_back]);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, vl._weights[_front]);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, vl._qTraces[_back]);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, vl._qTraces[_front]);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, vld._size);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, vl._hiddenToVisible);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, vld._radius);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, weightAlpha);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, weightLambda);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, reward);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, gamma);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, activeRatio);
_learnWeightsTracesInhibitedKernel.setArg(argIndex++, noise);
cs.getQueue().enqueueNDRangeKernel(_learnWeightsTracesInhibitedKernel, cl::NullRange, cl::NDRange(_hiddenSize.x, _hiddenSize.y));
std::swap(vl._weights[_front], vl._weights[_back]);
std::swap(vl._qTraces[_front], vl._qTraces[_back]);
}
}
示例9: sumSpikes
void HEInet::sumSpikes(sys::ComputeSystem &cs, float scalar) {
int index = 0;
_kernels->_sumSpikesKernel.setArg(index++, _eiLayers.front()._eLayer._states);
_kernels->_sumSpikesKernel.setArg(index++, _eSpikeSumsPrev);
_kernels->_sumSpikesKernel.setArg(index++, _eSpikeSums);
_kernels->_sumSpikesKernel.setArg(index++, scalar);
cs.getQueue().enqueueNDRangeKernel(_kernels->_sumSpikesKernel, cl::NullRange, cl::NDRange(_eiLayers.front().getConfig()._eWidth, _eiLayers.front().getConfig()._eHeight));
index = 0;
_kernels->_sumSpikesKernel.setArg(index++, _eiLayers.front()._iLayer._states);
_kernels->_sumSpikesKernel.setArg(index++, _iSpikeSumsPrev);
_kernels->_sumSpikesKernel.setArg(index++, _iSpikeSums);
_kernels->_sumSpikesKernel.setArg(index++, scalar);
cs.getQueue().enqueueNDRangeKernel(_kernels->_sumSpikesKernel, cl::NullRange, cl::NDRange(_eiLayers.front().getConfig()._iWidth, _eiLayers.front().getConfig()._iHeight));
}
示例10: clearMemory
void AgentSwarm::clearMemory(sys::ComputeSystem &cs) {
cl_float4 zeroColor = { 0.0f, 0.0f, 0.0f, 0.0f };
cl::array<cl::size_type, 3> zeroOrigin = { 0, 0, 0 };
for (int l = 0; l < _layers.size(); l++) {
cl::array<cl::size_type, 3> layerRegion = { _layerDescs[l]._hiddenSize.x, _layerDescs[l]._hiddenSize.y, 1 };
cs.getQueue().enqueueFillImage(_layers[l]._scHiddenStatesPrev, zeroColor, zeroOrigin, layerRegion);
}
}
示例11: setInputPhase
void HEInet::setInputPhase(sys::ComputeSystem &cs, cl_uint4 color) {
cl::size_t<3> zeroCoord;
zeroCoord[0] = zeroCoord[1] = zeroCoord[2] = 0;
cl::size_t<3> eFeedForwardDimsCoord;
eFeedForwardDimsCoord[0] = _eiLayers.front().getConfig()._eFeedForwardWidth;
eFeedForwardDimsCoord[1] = _eiLayers.front().getConfig()._eFeedForwardHeight;
eFeedForwardDimsCoord[2] = 1;
cs.getQueue().enqueueFillImage(_inputSpikeTimersPrev, color, zeroCoord, eFeedForwardDimsCoord);
}
示例12: spikeSumBegin
void HEInet::spikeSumBegin(sys::ComputeSystem &cs) {
cl_float4 zeroColor = { 0.0f, 0.0f, 0.0f, 0.0f };
cl::size_t<3> zeroCoord;
zeroCoord[0] = zeroCoord[1] = zeroCoord[2] = 0;
cl::size_t<3> eDims;
eDims[0] = _eiLayers.front().getConfig()._eWidth;
eDims[1] = _eiLayers.front().getConfig()._eHeight;
eDims[2] = 1;
cl::size_t<3> iDims;
iDims[0] = _eiLayers.front().getConfig()._iWidth;
iDims[1] = _eiLayers.front().getConfig()._iHeight;
iDims[2] = 1;
cs.getQueue().enqueueFillImage(_eSpikeSums, zeroColor, zeroCoord, eDims);
cs.getQueue().enqueueFillImage(_eSpikeSumsPrev, zeroColor, zeroCoord, eDims);
cs.getQueue().enqueueFillImage(_iSpikeSums, zeroColor, zeroCoord, iDims);
cs.getQueue().enqueueFillImage(_iSpikeSumsPrev, zeroColor, zeroCoord, iDims);
}
示例13: randomUniform
void neo::randomUniform(cl::Image3D &image3D, sys::ComputeSystem &cs, cl::Kernel &randomUniform3DKernel, cl_int3 size, cl_float2 range, std::mt19937 &rng) {
int argIndex = 0;
std::uniform_int_distribution<int> seedDist;
cl_uint2 seed = { seedDist(rng), seedDist(rng) };
randomUniform3DKernel.setArg(argIndex++, image3D);
randomUniform3DKernel.setArg(argIndex++, seed);
randomUniform3DKernel.setArg(argIndex++, range);
cs.getQueue().enqueueNDRangeKernel(randomUniform3DKernel, cl::NullRange, cl::NDRange(size.x, size.y, size.z));
}
示例14: clearMemory
void HTFE::clearMemory(sys::ComputeSystem &cs) {
// ------------------------------------------------------------------------------
// -------------------------------- Clear Memory --------------------------------
// ------------------------------------------------------------------------------
cl_uint4 clear = { 0, 0, 0, 0 };
for (int l = 0; l < _layers.size(); l++) {
cl::size_t<3> origin;
origin[0] = 0;
origin[1] = 0;
origin[2] = 0;
cl::size_t<3> region;
region[0] = _layerDescs[l]._width;
region[1] = _layerDescs[l]._height;
region[2] = 1;
cs.getQueue().enqueueFillImage(_layers[l]._hiddenStatesFeedBackPrevPrev, clear, origin, region);
cs.getQueue().enqueueFillImage(_layers[l]._hiddenStatesFeedBackPrev, clear, origin, region);
cs.getQueue().enqueueFillImage(_layers[l]._hiddenStatesFeedBack, clear, origin, region);
}
}
示例15: reconstruct
void ComparisonSparseCoder::reconstruct(sys::ComputeSystem &cs, const cl::Image2D &hiddenStates, int visibleLayerIndex, cl::Image2D &visibleStates) {
VisibleLayer &vl = _visibleLayers[visibleLayerIndex];
VisibleLayerDesc &vld = _visibleLayerDescs[visibleLayerIndex];
int argIndex = 0;
_forwardKernel.setArg(argIndex++, hiddenStates);
_forwardKernel.setArg(argIndex++, visibleStates);
_forwardKernel.setArg(argIndex++, vl._weights[_back]);
_forwardKernel.setArg(argIndex++, vld._size);
_forwardKernel.setArg(argIndex++, _hiddenSize);
_forwardKernel.setArg(argIndex++, vl._visibleToHidden);
_forwardKernel.setArg(argIndex++, vl._hiddenToVisible);
_forwardKernel.setArg(argIndex++, vld._radius);
_forwardKernel.setArg(argIndex++, vl._reverseRadii);
cs.getQueue().enqueueNDRangeKernel(_forwardKernel, cl::NullRange, cl::NDRange(vld._size.x, vld._size.y));
}