ExecutionStatus execute(NodeSocketReader& reader, NodeSocketWriter& writer) override { const clw::Image2D& input = reader.readSocket(0).getDeviceImageMono(); clw::Image2D& output = writer.acquireSocket(0).getDeviceImageMono(); int imageWidth = input.width(); int imageHeight = input.height(); if(imageWidth == 0 || imageHeight == 0) return ExecutionStatus(EStatus::Ok); clw::Kernel kernelConvertBayer2Gray; switch(_BayerCode.cast<Enum>().cast<cvu::EBayerCode>()) { case cvu::EBayerCode::RG: kernelConvertBayer2Gray = _gpuComputeModule->acquireKernel(_kidConvertRG2Gray); break; case cvu::EBayerCode::GB: kernelConvertBayer2Gray = _gpuComputeModule->acquireKernel(_kidConvertGB2Gray); break; case cvu::EBayerCode::GR: kernelConvertBayer2Gray = _gpuComputeModule->acquireKernel(_kidConvertGR2Gray); break; case cvu::EBayerCode::BG: kernelConvertBayer2Gray = _gpuComputeModule->acquireKernel(_kidConvertBG2Gray); break; } if(kernelConvertBayer2Gray.isNull()) return ExecutionStatus(EStatus::Error, "Bad bayer code"); // Ensure output image size is enough if(output.isNull() || output.width() != imageWidth || output.height() != imageHeight) { output = _gpuComputeModule->context().createImage2D( clw::EAccess::ReadWrite, clw::EMemoryLocation::Device, clw::ImageFormat(clw::EChannelOrder::R, clw::EChannelType::Normalized_UInt8), imageWidth, imageHeight); } cl_float3 gains = { (float) _redGain, (float) _greenGain, (float) _blueGain }; int sharedWidth = 16 + 2; int sharedHeight = 16 + 2; kernelConvertBayer2Gray.setLocalWorkSize(16, 16); kernelConvertBayer2Gray.setRoundedGlobalWorkSize(imageWidth, imageHeight); kernelConvertBayer2Gray.setArg(0, input); kernelConvertBayer2Gray.setArg(1, output); kernelConvertBayer2Gray.setArg(2, gains); kernelConvertBayer2Gray.setArg(3, clw::LocalMemorySize(sharedWidth*sharedHeight*sizeof(float))); kernelConvertBayer2Gray.setArg(4, sharedWidth); kernelConvertBayer2Gray.setArg(5, sharedHeight); _gpuComputeModule->queue().asyncRunKernel(kernelConvertBayer2Gray); _gpuComputeModule->queue().finish(); return ExecutionStatus(EStatus::Ok); }
ExecutionStatus execute(NodeSocketReader& reader, NodeSocketWriter& writer) override { // Read input sockets const KeyPoints& kp = reader.readSocket(0).getKeypoints(); // Validate inputs if(kp.kpoints.empty() || kp.image.empty()) return ExecutionStatus(EStatus::Ok); // Acquire output sockets KeyPoints& outKp = writer.acquireSocket(0).getKeypoints(); cv::Mat& outDescriptors = writer.acquireSocket(1).getArray(); outKp = kp; // Do stuff cv::SiftDescriptorExtractor extractor; extractor.compute(kp.image, outKp.kpoints, outDescriptors); return ExecutionStatus(EStatus::Ok); }
ExecutionStatus execute(NodeSocketReader& reader, NodeSocketWriter& writer) override { // Read input sockets const cv::Mat& src = reader.readSocket(0).getImageMono(); // Acquire output sockets KeyPoints& kp = writer.acquireSocket(0).getKeypoints(); // Validate inputs if(src.empty()) return ExecutionStatus(EStatus::Ok); // Do stuff cv::SiftFeatureDetector detector(_nFeatures, _nOctaveLayers, _contrastThreshold, _edgeThreshold, _sigma); detector.detect(src, kp.kpoints); kp.image = src; return ExecutionStatus(EStatus::Ok, string_format("Keypoints detected: %d", (int) kp.kpoints.size())); }
ExecutionStatus execute(NodeSocketReader& reader, NodeSocketWriter&) override { // Read input sockets const cv::Mat& input = reader.readSocket(0).getImage(); // Validate inputs if(input.empty()) return ExecutionStatus(EStatus::Ok); if(!_writer.isOpened()) { bool isColor = input.channels() == 3; _writer.open(_filename.cast<Filepath>().data(), getFOURCC(_fourcc), _fps, input.size(), isColor); if(!_writer.isOpened()) return ExecutionStatus(EStatus::Error, string_format("Couldn't open video writer for file %s", _filename.cast<Filepath>().data().c_str())); } _writer << input; return ExecutionStatus(EStatus::Ok); }
void ReplicatedMergeTreeBlockOutputStream::write(const Block & block) { last_block_is_duplicate = false; /// TODO Is it possible to not lock the table structure here? storage.data.delayInsertOrThrowIfNeeded(&storage.partial_shutdown_event); auto zookeeper = storage.getZooKeeper(); assertSessionIsNotExpired(zookeeper); /** If write is with quorum, then we check that the required number of replicas is now live, * and also that for all previous parts for which quorum is required, this quorum is reached. * And also check that during the insertion, the replica was not reinitialized or disabled (by the value of `is_active` node). * TODO Too complex logic, you can do better. */ if (quorum) checkQuorumPrecondition(zookeeper); auto part_blocks = storage.writer.splitBlockIntoParts(block); for (auto & current_block : part_blocks) { Stopwatch watch; /// Write part to the filesystem under temporary name. Calculate a checksum. MergeTreeData::MutableDataPartPtr part = storage.writer.writeTempPart(current_block); String block_id; if (deduplicate) { SipHash hash; part->checksums.computeTotalChecksumDataOnly(hash); union { char bytes[16]; UInt64 words[2]; } hash_value; hash.get128(hash_value.bytes); /// We add the hash from the data and partition identifier to deduplication ID. /// That is, do not insert the same data to the same partition twice. block_id = part->info.partition_id + "_" + toString(hash_value.words[0]) + "_" + toString(hash_value.words[1]); LOG_DEBUG(log, "Wrote block with ID '" << block_id << "', " << block.rows() << " rows"); } else { LOG_DEBUG(log, "Wrote block with " << block.rows() << " rows"); } try { commitPart(zookeeper, part, block_id); /// Set a special error code if the block is duplicate int error = (deduplicate && last_block_is_duplicate) ? ErrorCodes::INSERT_WAS_DEDUPLICATED : 0; PartLog::addNewPart(storage.context, part, watch.elapsed(), ExecutionStatus(error)); } catch (...) { PartLog::addNewPart(storage.context, part, watch.elapsed(), ExecutionStatus::fromCurrentException(__PRETTY_FUNCTION__)); throw; } } }
ExecutionStatus execute(NodeSocketReader& reader, NodeSocketWriter& writer) override { const clw::Image2D& deviceImage = reader.readSocket(0).getDeviceImageMono(); clw::Image2D& deviceDest = writer.acquireSocket(0).getDeviceImageMono(); int srcWidth = deviceImage.width(); int srcHeight = deviceImage.height(); if(srcWidth == 0 || srcHeight == 0) return ExecutionStatus(EStatus::Ok); clw::Kernel kernelGaussMix = _gpuComputeModule->acquireKernel(_kidGaussMix); /* Create mixture data buffer */ resetMixturesState(srcWidth * srcHeight); if(deviceDest.isNull() || deviceDest.width() != srcWidth || deviceDest.height() != srcHeight) { // Obraz (w zasadzie maska) pierwszego planu deviceDest = _gpuComputeModule->context().createImage2D( clw::EAccess::ReadWrite, clw::EMemoryLocation::Device, clw::ImageFormat(clw::EChannelOrder::R, clw::EChannelType::Normalized_UInt8), srcWidth, srcHeight); } // Calculate dynamic learning rate (if necessary) ++_nframe; float alpha = _learningRate >= 0 && _nframe > 1 ? _learningRate : 1.0f/std::min(_nframe, _history.cast<int>()); kernelGaussMix.setLocalWorkSize(16, 16); kernelGaussMix.setRoundedGlobalWorkSize(srcWidth, srcHeight); kernelGaussMix.setArg(0, deviceImage); kernelGaussMix.setArg(1, deviceDest); kernelGaussMix.setArg(2, _mixtureDataBuffer); kernelGaussMix.setArg(3, _mixtureParamsBuffer); kernelGaussMix.setArg(4, alpha); _gpuComputeModule->queue().asyncRunKernel(kernelGaussMix); if(_showBackground) { clw::Image2D& deviceDestBackground = writer.acquireSocket(1).getDeviceImageMono(); if(deviceDestBackground.isNull() || deviceDestBackground.width() != srcWidth || deviceDestBackground.height() != srcHeight) { // Obraz (w zasadzie maska) pierwszego planu deviceDestBackground = _gpuComputeModule->context().createImage2D( clw::EAccess::ReadWrite, clw::EMemoryLocation::Device, clw::ImageFormat(clw::EChannelOrder::R, clw::EChannelType::Normalized_UInt8), srcWidth, srcHeight); } clw::Kernel kernelBackground = _gpuComputeModule->acquireKernel(_kidGaussBackground); kernelBackground.setLocalWorkSize(16, 16); kernelBackground.setRoundedGlobalWorkSize(srcWidth, srcHeight); kernelBackground.setArg(0, deviceDestBackground); kernelBackground.setArg(1, _mixtureDataBuffer); kernelBackground.setArg(2, _mixtureParamsBuffer); _gpuComputeModule->queue().asyncRunKernel(kernelBackground); } _gpuComputeModule->queue().finish(); return ExecutionStatus(EStatus::Ok); }
ExecutionStatus ExecutionStatus::fromCurrentException(const std::string & start_of_message) { String msg = (start_of_message.empty() ? "" : (start_of_message + ": ")) + getCurrentExceptionMessage(false, true); return ExecutionStatus(getCurrentExceptionCode(), msg); }
ExecutionStatus Event::get_Status() { cl_int r; ClCheck(::clGetEventInfo(Handle(), CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof r, &r, 0)); return ExecutionStatus(r); }