void CudnnConvLayer::forward(PassType passType) { Layer::forward(passType); int batchSize = getInput(0).getBatchSize(); resetOutput(batchSize, calOutputSize()); for (size_t i = 0; i != inputLayers_.size(); ++i) { projections_[i]->forward(&getInput(i), &getOutput(), passType); } if (biases_) { REGISTER_TIMER_INFO("CudnnConvBiasTimer", getName().c_str()); int batchSize = inputLayers_[0]->getOutputValue()->getHeight(); hl_tensor_reshape(outputDesc_, batchSize, numFilters_ / groups_[0], outputH_[0], outputW_[0], numFilters_ * outputH_[0] * outputW_[0], outputH_[0] * outputW_[0], outputW_[0], 1); outputOffset_ = getOutputValue()->getWidth() / groups_[0]; for (int g = 0; g < groups_[0]; ++g) { real *biasData = biases_->getW()->getData() + biasOffset_ * g; real *outData = getOutputValue()->getData() + outputOffset_ * g; hl_convolution_forward_add_bias(biasDesc_, biasData, outputDesc_, outData); } } forwardActivation(); }
void InterpolationLayer::forward(PassType passType) { Layer::forward(passType); MatrixPtr weightV = getInputValue(0); MatrixPtr inV1 = getInputValue(1); MatrixPtr inV2 = getInputValue(2); size_t batchSize = inV1->getHeight(); size_t dataDim = inV1->getWidth(); CHECK_EQ(dataDim, getSize()); CHECK_EQ(dataDim, inV2->getWidth()); CHECK_EQ(batchSize, inV1->getHeight()); CHECK_EQ(batchSize, inV2->getHeight()); { REGISTER_TIMER_INFO("FwResetTimer", getName().c_str()); resetOutput(batchSize, dataDim); } MatrixPtr outV = getOutputValue(); Matrix::resizeOrCreate(weightLast_, batchSize, 1, false, useGpu_); weightLast_->one(); weightLast_->sub(*weightV); REGISTER_TIMER_INFO("FwInterpTimer", getName().c_str()); // outV = inV1 * weight + inV2 * weightLast outV->addRowScale(0, *inV1, *weightV); outV->addRowScale(0, *inV2, *weightLast_); }
void GatedRecurrentLayer::forward(PassType passType) { REGISTER_TIMER_INFO("GruFwTimer", getName().c_str()); Layer::forward(passType); const Argument& input = getInput(0); CHECK(input.sequenceStartPositions); int batchSize = input.getBatchSize(); size_t numSequences = input.getNumSequences(); resetOutput(batchSize, getSize()); CHECK_EQ(getSize() * 3, input.value->getWidth()); const int* starts = input.sequenceStartPositions->getData(false); // batchSize = length of total frames in a batch (NOT size of mini-batch) CHECK_EQ(starts[numSequences], batchSize); Matrix::resizeOrCreate(gate_.value, /* height= */batchSize, getSize() * 3, /* trans= */false, useGpu_); Matrix::resizeOrCreate(resetOutput_.value, /* height= */batchSize, getSize(), /* trans= */false, useGpu_); if (useBatch_) { forwardBatch(batchSize, numSequences, starts, input.value); } else { forwardSequence(batchSize, numSequences, starts, input.value); } }
///////// // // Parse and interpret a stream, and return its value // // This is used in doCommand to execute a passed-in or collected text command, // in domacrocommand() when a macro/function is called from within a parse stream, // and in runBackgroundTasks to kick off the background run. // // numvar execscript(byte scripttype, numvar scriptaddress, char *scriptname) { // save parse context parsepoint fetchmark; markparsepoint(&fetchmark); byte thesym = sym; vpush(symval); // if this is the first stream context in this invocation, // set up our error recovery point and init the value stack // otherwise we skip this to allow nested execution calls // to properly return to top // if (fetchtype == SCRIPT_NONE) { // Exceptions come here via longjmp; see bitlash-error.c switch(setjmp(env)) { case 0: break; case X_EXIT: { // POLICY: Stop all background tasks on any error // // It is not possible to be certain that continuing here will work. // Not all errors leave the interpreter in a working state. Though most do. // The conservative/deterministic choice is to stop all background tasks // and drop the user back to the command prompt. // // On the other hand, you may find this inconvenient in your application, // and may be happy taking the risk of continuing. // // In which case, comment out this line and proceed with caution. // // TODO: if the macro "onerror" exists, call it here instead. Let it "stop *". // // -br // initTaskList(); // stop all pending tasks #ifdef SOFTWARE_SERIAL_TX resetOutput(); // clean up print module #endif // Other cleanups here vinit(); // initialize the expression stack fetchtype = SCRIPT_NONE; // reset parse context fetchptr = 0L; // reset parse location // sd_up = 0; // TODO: reset file system return (numvar) -1; } // X_EXIT case } // switch } initparsepoint(scripttype, scriptaddress, scriptname); getsym(); // interpret the function text and collect its result numvar ret = getstatementlist(); returntoparsepoint(&fetchmark, 1); // now where were we? sym = thesym; symval = vpop(); return ret; }
void ScaleSubRegionLayer::forward(PassType passType) { Layer::forward(passType); auto in0 = getInput(0); imgH_ = in0.getFrameHeight(); imgW_ = in0.getFrameWidth(); if (imgH_ == 0 || imgW_ == 0) { auto& conf = config_.inputs(0).scale_sub_region_conf(); imgH_ = conf.image_conf().img_size_y(); imgW_ = conf.image_conf().img_size(); } MatrixPtr imgV = in0.value; size_t batchSize = imgV->getHeight(); size_t spatialSize = imgH_ * imgW_; channelsNum_ = imgV->getWidth() / spatialSize; shape_ = TensorShape({batchSize, channelsNum_, imgH_, imgW_}); resetOutput(batchSize, imgV->getWidth()); auto& out = getOutput(); out.setFrameHeight(imgH_); out.setFrameWidth(imgW_); MatrixPtr indicesV = getInputValue(1); indicesShape_ = TensorShape({batchSize, 6}); REGISTER_TIMER_INFO("ScaleSubRegionForward", getName().c_str()); BufferArgs inArgs; BufferArgs outArgs; inArgs.addArg(*imgV, shape_); inArgs.addArg(*indicesV, indicesShape_); outArgs.addArg(*out.value, shape_, ASSIGN_TO); forward_[0]->calc(inArgs, outArgs); }
void BlockExpandLayer::forward(PassType passType) { Layer::forward(passType); size_t batchSize = inputLayers_[0]->getOutputValue()->getHeight(); size_t blockNum = getBlockNum(); size_t blockSize = blockH_ * blockW_ * channels_; resetOutput(blockNum * batchSize, blockSize); // calculate output_.value inputShape_ = TensorShape({batchSize, channels_, imgSizeH_, imgSizeW_}); outputShape_ = TensorShape({batchSize, blockNum, blockSize}); BufferArgs inputs; BufferArgs outputs; inputs.addArg(*getInputValue(0), inputShape_); outputs.addArg(*getOutputValue(), outputShape_, ASSIGN_TO); forward_[0]->calc(inputs, outputs); // calculate output_.sequenceStartPositions and output_.cpuSequenceDims Argument& out = getOutput(); ICpuGpuVector::resizeOrCreate( out.sequenceStartPositions, batchSize + 1, false); IVector::resizeOrCreate(out.cpuSequenceDims, 2 * batchSize, false); int* start = out.sequenceStartPositions->getMutableData(false); int* dims = out.cpuSequenceDims->getData(); for (size_t i = 0; i < batchSize; i++) { start[i] = i * blockNum; dims[2 * i] = outputH_; dims[2 * i + 1] = outputW_; } start[batchSize] = batchSize * blockNum; }
void ConcatenateLayer2::forward(PassType passType) { Layer::forward(passType); int batchSize = getInput(0).getBatchSize(); int size = getSize(); resetOutput(batchSize, size); for (size_t i = 0; i < projections_.size(); i++) { size_t startCol = projCol_[i].first; size_t endCol = projCol_[i].second; projOutput_[i].value = output_.value->subColMatrix(startCol, endCol); if (output_.grad) { projOutput_[i].grad = output_.grad->subColMatrix(startCol, endCol); } } { AsyncGpuBlock block; for (size_t i = 0; i != inputLayers_.size(); ++i) { projections_[i]->forward(&getInput(i), &projOutput_[i], passType); } } /* add the bias-vector */ if (biases_) { REGISTER_TIMER_INFO("FwBiasTimer", getName().c_str()); output_.value->addBias(*(biases_->getW()), 1, sharedBias_); } /* activation */ { REGISTER_TIMER_INFO("FwAtvTimer", getName().c_str()); forwardActivation(); } }
void forward(PassType passType) override { Layer::forward(passType); CHECK(!useGpu_) << "GPU is not supported"; if (!prepared_) { if (passType == PASS_GC) { ThreadLocalRandomEngine::get().seed(ThreadLocalRand::getDefaultSeed()); } prepareSamples(); } prepared_ = false; /* malloc memory for the output_ if necessary */ int batchSize = getInputValue(0)->getHeight(); int size = getSize(); resetOutput(batchSize, size); Matrix::resizeOrCreate(sampleOut_.value, 1, samples_.size(), /* trans= */ false, useGpu_); forwardBias(); for (int l = 0; l < numInputs_; ++l) { forwardOneInput(l); } auto status = activation_->forward(sampleOut_); status.check(); forwardCost(); }
void ADSREnvelopeChip::tickOutput() { if (clockInputRegister.getRisingEdge()) clockOutput(); if (resetInputRegister.getRisingEdge()) resetOutput(); }
HeatSink::~HeatSink() { _adcTimer->stop(); resetOutput(); delete _fan; delete _adcTimer; }
HeatSink::HeatSink(Settings settings, const std::string &fanPWMPath, unsigned long fanPWMPeriod, const ADCPin &adcPin) :TemperatureController(settings), _adcPin(adcPin) { _fan = new PWMControl(fanPWMPath, fanPWMPeriod); _adcTimer = new Poco::Timer; _fan->setPWMDutyCycle((unsigned long)0); resetOutput(); }
/* Returnera n�sta element i k�n, generera mera om det beh�vs */ OUTPUT *memIndirect(void) { if(curritem>=nitems) { resetOutput(); doSomeMore(); } if(curritem<nitems) return &out[curritem++]; else return NULL; }
/* Returnera n�sta element i k�n, generera mera om det beh�vs */ OUTPUT *opModes(void) { if(curritem>=nitems) { resetOutput(); doOpModes(); } if(curritem<nitems) return &out[curritem++]; else return NULL; }
/* Returnera n�sta element i k�n, generera mera om det beh�vs */ OUTPUT *simple68(void) { if(curritem>=nitems) { resetOutput(); doSomeMore(); } if(curritem<nitems) return &out[curritem++]; else return NULL; }
void Drm::deinitialize() { for (int i = 0; i < OUTPUT_MAX; i++) { resetOutput(i); } if (mDrmFd) { close(mDrmFd); mDrmFd = 0; } mInitialized = false; }
void MaxOutLayer::forward(PassType passType) { Layer::forward(passType); /* malloc memory for the output_ if necessary */ /* note: one sample correspond to one column */ size_t batchSize = getInput(0).getBatchSize(); size_t size = getSize(); resetOutput(batchSize, size); MatrixPtr inputV = getInputValue(0); MatrixPtr outV = getOutputValue(); IVector::resizeOrCreate(maxoutId_, size * batchSize, useGpu_); outV->maxoutForward(*inputV, *maxoutId_, outputChannels_, groups_); }
void DeConv3DLayer::forward(PassType passType) { Layer::forward(passType); int batchSize = inputLayers_[0]->getOutputValue()->getHeight(); int outWidth = getSize(); resetOutput(batchSize, outWidth); const MatrixPtr outMat = getOutputValue(); REGISTER_TIMER_INFO("FwdDeConv3D", getName().c_str()); for (size_t i = 0; i != inputLayers_.size(); ++i) { const MatrixPtr &inMat = getInputValue(i); int M = M_[i]; int N = N_[i]; int K = K_[i]; MatrixPtr wMat = weights_[i]->getW(); Matrix::resizeOrCreate(colBuf_, K * groups_[i], N, false, useGpu_); for (int n = 0; n < batchSize; ++n) { real *inData = inMat->getData() + n * inMat->getStride(); for (int g = 0; g < groups_[i]; ++g) { MatrixPtr inMatSub = Matrix::create(inData, M, N, false, useGpu_); MatrixPtr wMatSub = wMat->subMatrix(g * K, K); MatrixPtr colBufDataSub = colBuf_->subMatrix(g * K, K); colBufDataSub->mul(*wMatSub, *inMatSub, 1.0, 0.0); inData += M * N; } colBuf_->col2Vol(outMat->getData() + n * outMat->getStride(), numFilters_, imgSizeD_[i], imgSizeH_[i], imgSizeW_[i], filterSizeZ_[i], filterSizeY_[i], filterSize_[i], strideZ_[i], strideY_[i], stride_[i], paddingZ_[i], paddingY_[i], padding_[i], 1.0, 1.0); } } if (nullptr != this->biasParameter_) { this->addBias(); } forwardActivation(); }
void FeatureMapExpandLayer::forward(PassType passType) { Layer::forward(passType); MatrixPtr inputV = getInputValue(0); size_t batchSize = getInput(0).getBatchSize(); int imgSize = inputV->getWidth(); resetOutput(batchSize, imgSize * numFilters_); MatrixPtr outputV = getOutputValue(); { AsyncGpuBlock asyncGpuBlock; if (asRowVector_) { for (size_t i = 0; i < batchSize; i++) { MatrixPtr outVTmp = Matrix::create(outputV->getData() + i * imgSize * numFilters_, numFilters_, imgSize, false, useGpu_); MatrixPtr inVTmp = Matrix::create( inputV->getData() + i * imgSize, 1, imgSize, false, useGpu_); outVTmp->addRowVector(*inVTmp); } } else { for (size_t i = 0; i < batchSize; i++) { MatrixPtr outVTmp = Matrix::create(outputV->getData() + i * imgSize * numFilters_, imgSize, numFilters_, false, useGpu_); MatrixPtr inVTmp = Matrix::create( inputV->getData() + i * imgSize, imgSize, 1, false, useGpu_); outVTmp->addColVector(*inVTmp); } } } /* activation */ { REGISTER_TIMER_INFO("FwAtvTimer", getName().c_str()); forwardActivation(); } }
bool KALPhonon::setCategory( Phonon::Category category ) { resetOutput(); // An instance of QCoreApplication must be running to create a Phonon::AudioOutput if( !QCoreApplication::instance() ) { qWarning() << "Could not get current Phonon device because QCoreApplication is not running"; return false; } d->phononOutput = new Phonon::AudioOutput( category, this ); if( !setDevice( d->phononOutput->outputDevice() ) ) { return false; } d->category = category; connect( d->phononOutput, SIGNAL( outputDeviceChanged( Phonon::AudioOutputDevice ) ), this, SLOT( setDevice( Phonon::AudioOutputDevice ) ) ); return true; }
void MixedLayer::forward(PassType passType) { Layer::forward(passType); int batchSize = getInput(0).getBatchSize(); int size = getSize(); { REGISTER_TIMER_INFO("FwResetTimer", getName().c_str()); resetOutput(batchSize, size); } MatrixPtr outV = getOutputValue(); for (size_t i = 0; i != inputLayers_.size(); ++i) { if (projections_[i]) { projections_[i]->forward(&getInput(i), &output_, passType); } } std::vector<const Argument*> ins; for (auto& op : operators_) { ins.clear(); for (auto& input_index : op->getConfig().input_indices()) { ins.push_back(&getInput(input_index)); } op->forward(ins, &output_, passType); } /* add the bias-vector */ if (biases_.get() != NULL) { REGISTER_TIMER_INFO("FwBiasTimer", getName().c_str()); outV->addBias(*(biases_->getW()), 1, sharedBias_); } /* activation */ { REGISTER_TIMER_INFO("FwAtvTimer", getName().c_str()); forwardActivation(); } }
void PHPBackend::gotOutput (KProcess *, char* buf, int len) { RK_TRACE (PHP); QString output = buf; QString request; QString data; int i; bool have_data = true;; bool have_request = false; // is there a request in the output stream? if ((i = output.find (eot_string)) >= 0) { have_request = true; // is there also pending data? if (i) { data = output.left (i); } else { have_data = false; } request = output.mid (i + eot_string.length (), len); } else { data = output; } RK_DO (qDebug ("request: %s\ndata: %s", request.latin1 (), data.latin1 ()), PHP, DL_DEBUG); // pending data is always first in a stream, so process it first, too if (have_data) { if (!startup_done) { php_process->detach (); KMessageBox::error (0, i18n ("There has been an error\n(\"%1\")\nwhile starting up the PHP backend. Most likely this is due to either a bug in RKWard or an invalid setting for the location of the PHP support files. Check the settings (Settings->Configure Settings->PHP backend) and try again.").arg (data.stripWhiteSpace ()), i18n ("PHP-Error")); emit (haveError ()); destroy (); return; } _output.append (data); } if (have_request) { if (request == "requesting code") { startup_done = true; busy = false; RK_DO (qDebug ("got type: %d, stack %d", current_type, command_stack.count ()), PHP, DL_DEBUG); if (current_type != Ignore) { if (code_property) { if (_output.isNull ()) _output = ""; // must not be null for the code property! if (current_type == Preprocess) { if (add_headings) code_property->setPreprocess (i18n ("## Prepare\n") + retrieveOutput ()); else code_property->setPreprocess (retrieveOutput ()); resetOutput (); } else if (current_type == Calculate) { if (add_headings) code_property->setCalculate (i18n ("## Compute\n") + retrieveOutput ()); else code_property->setCalculate (retrieveOutput ()); resetOutput (); } else if (current_type == Printout) { if (add_headings) code_property->setPrintout (i18n ("## Print result\n") + retrieveOutput ()); else code_property->setPrintout (retrieveOutput ()); resetOutput (); } else if (current_type == Cleanup) { if (add_headings) code_property->setCleanup (i18n ("## Clean up\n") + retrieveOutput ()); else code_property->setCleanup (retrieveOutput ()); resetOutput (); } else { emit (commandDone (current_flags)); } } else { emit (commandDone (current_flags)); } } tryNextFunction (); if (!busy) { emit (idle ()); return; } } else if (request.startsWith ("requesting data:")) { QString requested_object = request.remove ("requesting data:"); RK_DO (qDebug ("requested data: \"%s\"", requested_object.latin1 ()), PHP, DL_DEBUG); emit (requestValue (requested_object)); busy = true; // writeData (res + eot_string); } else if (request.startsWith ("requesting rcall:")) { QString requested_call = request.remove ("requesting rcall:"); RK_DO (qDebug ("requested rcall: \"%s\"", requested_call.latin1 ()), PHP, DL_DEBUG); emit (requestRCall (requested_call)); busy = true; // _responsible->doRCall (requested_call); } else if (request.startsWith ("requesting rvector:")) { QString requested_call = request.remove ("requesting rvector:"); RK_DO (qDebug ("requested rvector: \"%s\"", requested_call.latin1 ()), PHP, DL_DEBUG); emit (requestRVector (requested_call)); busy = true; // _responsible->getRVector (requested_call); } else if (request.startsWith ("PHP-Error")) { QString error = request.remove ("PHP-Error"); php_process->detach (); KMessageBox::error (0, i18n ("The PHP-backend has reported an error\n(\"%1\")\nand has been shut down. This is most likely due to a bug in the plugin. But of course you may want to try to close and restart the plugin to see whether it works with different settings.").arg (error.stripWhiteSpace ()), i18n ("PHP-Error")); emit (haveError ()); destroy (); return; } return; } }
void DacChip::tickOutput() { if (resetInputRegister.getRisingEdge()) resetOutput(); }
Tester() { isInUnitTest = true; Options oldOptions = options; options = Options(Options::defaults); assert(isExtendedKey(VK_LEFT)); assert(isExtendedKey(VK_RMENU)); assert(!isExtendedKey(VK_F1)); assert(!isExtendedKey(0)); // normal (slow) typing resetOutput(); CHECK((SP, up, SP,up, 0)); CHECK((SP, dn, SP,up, 0)); CHECK((SP, up, SP,up, SP,dn, SP,up, 0)); CHECK((x, dn, SP,up, SP,dn, SP,up, x,dn, 0)); CHECK((x, up, SP,up, SP,dn, SP,up, x,dn, x,up, 0)); CHECK((j, dn, SP,up, SP,dn, SP,up, x,dn, x,up, j,dn, 0)); CHECK((j, up, SP,up, SP,dn, SP,up, x,dn, x,up, j,dn, j,up, 0)); // overlapped slightly resetOutput(); CHECK((SP, dn, 0)); CHECK((x, dn, SP,dn, x,dn, 0)); CHECK((SP, up, SP,dn, x,dn, SP,up, 0)); CHECK((x, up, SP,dn, x,dn, SP,up, x,up, 0)); //... plus repeating spaces resetOutput(); CHECK((SP, dn, 0)); CHECK((SP, dn, 0)); CHECK((j, dn, 0)); CHECK((SP, dn, 0)); CHECK((SP, up, SP,dn, j,dn, SP,up, 0)); CHECK((j, up, SP,dn, j,dn, SP,up, j,up, 0)); // key ups in waitMappedDown resetOutput(); CHECK((SP, dn, 0)); CHECK((x, up, x,up, 0)); CHECK((j, up, x,up, j,up, 0)); CHECK((SP, up, x,up, j,up, SP,dn, SP,up, 0)); // other keys in waitMappedUp resetOutput(); CHECK((SP, dn, 0)); CHECK((j, dn, 0)); CHECK((x, up, SP,dn, j,dn, x,up, 0)); CHECK((x, dn, SP,dn, j,dn, x,up, x,dn, 0)); CHECK((j, dn, SP,dn, j,dn, x,up, x,dn, j,dn, 0)); CHECK((SP, up, SP,dn, j,dn, x,up, x,dn, j,dn, SP,up, 0)); resetOutput(); CHECK((SP, dn, 0)); CHECK((j, dn, 0)); CHECK((x, dn, SP,dn, j,dn, x,dn, 0)); CHECK((SP, up, SP,dn, j,dn, x,dn, SP,up, 0)); // activate mapping resetOutput(); CHECK((SP, dn, 0)); CHECK((j, dn, 0)); CHECK((j, up, LE,edn, LE,up, 0)); CHECK((SP, up, LE,edn, LE,up, 0)); // autorepeat into mapping, and out resetOutput(); CHECK((SP, dn, 0)); CHECK((j, dn, 0)); CHECK((j, dn, LE,edn, LE,edn, 0)); CHECK((j, dn, LE,edn, LE,edn, LE,edn, 0)); CHECK((j, up, LE,edn, LE,edn, LE,edn, LE,up, 0)); CHECK((SP, dn, LE,edn, LE,edn, LE,edn, LE,up, 0)); CHECK((j, dn, LE,edn, LE,edn, LE,edn, LE,up, LE,edn, 0)); CHECK((SP, up, LE,edn, LE,edn, LE,edn, LE,up, LE,edn, LE,up, 0)); CHECK((j, dn, LE,edn, LE,edn, LE,edn, LE,up, LE,edn, LE,up, j,dn, 0)); CHECK((j, up, LE,edn, LE,edn, LE,edn, LE,up, LE,edn, LE,up, j,dn, j,up, 0)); // other keys during mapping resetOutput(); CHECK((SP, dn, 0)); CHECK((j, dn, 0)); CHECK((j, up, LE,edn, LE,up, 0)); CHECK((x, dn, LE,edn, LE,up, x,dn, 0)); CHECK((x, up, LE,edn, LE,up, x,dn, x,up, 0)); CHECK((j, dn, LE,edn, LE,up, x,dn, x,up, LE,edn, 0)); CHECK((SP, up, LE,edn, LE,up, x,dn, x,up, LE,edn, LE,up, 0)); // check space-emmitted states // wmdse resetOutput(); CHECK((SP, dn, 0)); CHECK((x, dn, SP,dn, x,dn, 0)); CHECK((SP, dn, SP,dn, x,dn, 0)); CHECK((x, dn, SP,dn, x,dn, x,dn, 0)); CHECK((x, up, SP,dn, x,dn, x,dn, x,up, 0)); CHECK((j, up, SP,dn, x,dn, x,dn, x,up, j,up, 0)); CHECK((j, dn, SP,dn, x,dn, x,dn, x,up, j,up, 0)); CHECK((j, up, SP,dn, x,dn, x,dn, x,up, j,up, LE,edn, LE,up, 0)); CHECK((SP, up, SP,dn, x,dn, x,dn, x,up, j,up, LE,edn, LE,up, 0)); //XXX should this emit a space (needs mappingSpaceEmitted state) // wmuse resetOutput(); CHECK((SP, dn, 0)); CHECK((x, dn, SP,dn, x,dn, 0)); CHECK((j, dn, SP,dn, x,dn, 0)); CHECK((SP, dn, SP,dn, x,dn, 0)); CHECK((SP, up, SP,dn, x,dn, j,dn, SP,up, 0)); resetOutput(); CHECK((SP, dn, 0)); CHECK((x, dn, SP,dn, x,dn, 0)); CHECK((j, dn, SP,dn, x,dn, 0)); CHECK((j, dn, SP,dn, x,dn, LE,edn, LE,edn, 0)); CHECK((SP, up, SP,dn, x,dn, LE,edn, LE,edn, LE,up, 0)); //XXX should this emit a space (needs mappingSpaceEmitted state) resetOutput(); CHECK((SP, dn, 0)); CHECK((x, dn, SP,dn, x,dn, 0)); CHECK((j, dn, SP,dn, x,dn, 0)); CHECK((x, up, SP,dn, x,dn, x,up, 0)); CHECK((j, up, SP,dn, x,dn, x,up, LE,edn, LE,up, 0)); CHECK((SP, up, SP,dn, x,dn, x,up, LE,edn, LE,up, 0)); //XXX should this emit a space (needs mappingSpaceEmitted state) // run configure tests resetOutput(); //idle CHECK((F5, dn, F5,dn, 0)); CHECK((SP, dn, F5,dn, 0)); // wmd CHECK((F5, dn, F5,dn, '*',dn, 0)); CHECK((F5, up, F5,dn, '*',dn, F5,up, 0)); CHECK((j, dn, F5,dn, '*',dn, F5,up, 0)); // wmu CHECK((F5, dn, F5,dn, '*',dn, F5,up, '*',dn, 0)); CHECK((j, up, F5,dn, '*',dn, F5,up, '*',dn, LE,edn, LE,up, 0)); // mapping CHECK((F5, dn, F5,dn, '*',dn, F5,up, '*',dn, LE,edn, LE,up, '*',dn, 0)); CHECK((SP, up, F5,dn, '*',dn, F5,up, '*',dn, LE,edn, LE,up, '*',dn, 0)); resetOutput(); CHECK((SP, dn, 0)); // wmd CHECK((x, dn, SP,dn, x,dn, 0)); // wmd-se CHECK((F5, dn, SP,dn, x,dn, '*',dn, 0)); CHECK((j, dn, SP,dn, x,dn, '*',dn, 0)); // wmu-se CHECK((F5, dn, SP,dn, x,dn, '*',dn, '*',dn, 0)); CHECK((SP, up, SP,dn, x,dn, '*',dn, '*',dn, j,dn, SP,up, 0)); // Overlapping mapped keys resetOutput(); CHECK((SP, dn, 0)); CHECK((m, dn, 0)); CHECK((j, dn, DEL,edn, LE,edn, 0)); CHECK((j, up, DEL,edn, LE,edn, LE,up, 0)); CHECK((m, up, DEL,edn, LE,edn, LE,up, DEL,up, 0)); CHECK((SP, up, DEL,edn, LE,edn, LE,up, DEL,up, 0)); // Overlapping mapped keys -- space up first. // should release held mapped keys. (Fixes sticky Shift bug.) resetOutput(); CHECK((SP, dn, 0)); CHECK((m, dn, 0)); CHECK((j, dn, DEL,edn, LE,edn, 0)); // release order is in vk code order CHECK((SP, up, DEL,edn, LE,edn, LE,up, DEL,up, 0)); // mapped modifier keys options.keyMapping['C'] = ctrlFlag | 'C'; // ctrl+c resetOutput(); CHECK((SP, dn, 0)); CHECK((c, dn, 0)); CHECK((c, up, ctrl,dn, c,dn, ctrl,up, c,up, 0)); CHECK((c, dn, ctrl,dn, c,dn, ctrl,up, c,up, ctrl,dn, c,dn, ctrl,up, 0)); CHECK((c, up, ctrl,dn, c,dn, ctrl,up, c,up, ctrl,dn, c,dn, ctrl,up, c,up, 0)); CHECK((SP, up, ctrl,dn, c,dn, ctrl,up, c,up, ctrl,dn, c,dn, ctrl,up, c,up, 0)); // with modifier already down: resetOutput(); CHECK((SP, dn, 0)); CHECK((ctrl,dn, ctrl,dn, 0)); CHECK((c, dn, ctrl,dn, 0)); CHECK((c, up, ctrl,dn, c,dn, c,up, 0)); CHECK((ctrl,up, ctrl,dn, c,dn, c,up, ctrl,up, 0)); CHECK((SP,up, ctrl,dn, c,dn, c,up, ctrl,up, 0)); // training mode options.trainingMode = true; options.beepForMistakes = false; resetOutput(); CHECK((x, dn, x,dn, 0)); CHECK((x, up, x,dn, x,up, 0)); CHECK((LE, edn, x,dn, x,up, 0)); CHECK((LE, up, x,dn, x,up, 0)); // with modifier mapping resetOutput(); CHECK((c, dn, c,dn, 0)); CHECK((c, up, c,dn, c,up, 0)); CHECK((ctrl, dn, c,dn, c,up, ctrl,dn, 0)); CHECK((c, dn, c,dn, c,up, ctrl,dn, 0)); CHECK((c, up, c,dn, c,up, ctrl,dn, 0)); CHECK((ctrl, up, c,dn, c,up, ctrl,dn, ctrl,up, 0)); SM.printUnusedTransitions(); if (failures) exit(failures); else OutputDebugString(L"Unit tests passed\n"); options = oldOptions; isInUnitTest = false; }
bool Drm::detect(int device) { RETURN_FALSE_IF_NOT_INIT(); Mutex::Autolock _l(mLock); int outputIndex = getOutputIndex(device); if (outputIndex < 0 ) { return false; } resetOutput(outputIndex); // get drm resources drmModeResPtr resources = drmModeGetResources(mDrmFd); if (!resources) { ELOGTRACE("fail to get drm resources, error: %s", strerror(errno)); return false; } drmModeConnectorPtr connector = NULL; DrmOutput *output = &mOutputs[outputIndex]; bool ret = false; // find connector for the given device for (int i = 0; i < resources->count_connectors; i++) { if (!resources->connectors || !resources->connectors[i]) { ELOGTRACE("fail to get drm resources connectors, error: %s", strerror(errno)); continue; } connector = drmModeGetConnector(mDrmFd, resources->connectors[i]); if (!connector) { ELOGTRACE("drmModeGetConnector failed"); continue; } if (connector->connector_type != DrmConfig::getDrmConnector(device)) { drmModeFreeConnector(connector); continue; } if (connector->connection != DRM_MODE_CONNECTED) { ILOGTRACE("device %d is not connected", device); drmModeFreeConnector(connector); ret = true; break; } output->connector = connector; output->connected = true; // get proper encoder for the given connector if (connector->encoder_id) { ILOGTRACE("Drm connector has encoder attached on device %d", device); output->encoder = drmModeGetEncoder(mDrmFd, connector->encoder_id); if (!output->encoder) { ELOGTRACE("failed to get encoder from a known encoder id"); // fall through to get an encoder } } if (!output->encoder) { ILOGTRACE("getting encoder for device %d", device); drmModeEncoderPtr encoder; for (int j = 0; j < resources->count_encoders; j++) { if (!resources->encoders || !resources->encoders[j]) { ELOGTRACE("fail to get drm resources encoders, error: %s", strerror(errno)); continue; } encoder = drmModeGetEncoder(mDrmFd, resources->encoders[i]); if (!encoder) { ELOGTRACE("drmModeGetEncoder failed"); continue; } if (encoder->encoder_type == DrmConfig::getDrmEncoder(device)) { output->encoder = encoder; break; } drmModeFreeEncoder(encoder); encoder = NULL; } } if (!output->encoder) { ELOGTRACE("failed to get drm encoder"); break; } // get an attached crtc or spare crtc if (output->encoder->crtc_id) { ILOGTRACE("Drm encoder has crtc attached on device %d", device); output->crtc = drmModeGetCrtc(mDrmFd, output->encoder->crtc_id); if (!output->crtc) { ELOGTRACE("failed to get crtc from a known crtc id"); // fall through to get a spare crtc } } if (!output->crtc) { ILOGTRACE("getting crtc for device %d", device); drmModeCrtcPtr crtc; for (int j = 0; j < resources->count_crtcs; j++) { if (!resources->crtcs || !resources->crtcs[j]) { ELOGTRACE("fail to get drm resources crtcs, error: %s", strerror(errno)); continue; } crtc = drmModeGetCrtc(mDrmFd, resources->crtcs[j]); if (!crtc) { ELOGTRACE("drmModeGetCrtc failed"); continue; } // check if legal crtc to the encoder if (output->encoder->possible_crtcs & (1<<j)) { if (crtc->buffer_id == 0) { output->crtc = crtc; break; } } drmModeFreeCrtc(crtc); } } if (!output->crtc) { ELOGTRACE("failed to get drm crtc"); break; } // current mode if (output->crtc->mode_valid) { ILOGTRACE("mode is valid, kernel mode settings"); memcpy(&output->mode, &output->crtc->mode, sizeof(drmModeModeInfo)); //output->fbId = output->crtc->buffer_id; ret = true; } else { ELOGTRACE("mode is invalid. Kernel mode setting is not completed"); ret = false; } if (outputIndex == OUTPUT_PRIMARY) { if (!readIoctl(DRM_PSB_PANEL_ORIENTATION, &output->panelOrientation, sizeof(int))) { ELOGTRACE("failed to get device %d orientation", device); output->panelOrientation = PANEL_ORIENTATION_0; } } else { output->panelOrientation = PANEL_ORIENTATION_0; } break; } if (!ret) { if (output->connector == NULL && outputIndex != OUTPUT_PRIMARY) { // a fatal failure on primary device // non fatal on secondary device WLOGTRACE("device %d is disabled?", device); ret = true; } resetOutput(outputIndex); } else if (output->connected) { ILOGTRACE("mode is: %dx%d@%dHz", output->mode.hdisplay, output->mode.vdisplay, output->mode.vrefresh); } drmModeFreeResources(resources); return ret; }
MatchDetails::MatchDetails() : _elemMatchKeyRequested() { resetOutput(); }
Neuron::Neuron() { std::uniform_real_distribution<double> unif(init_neuron_lower_bound, init_neuron_upper_bound); shift = unif(::re); resetOutput(); resetError(); }