inline future<void> dispatch_fill_async(BufferIterator first, size_t count, const T &value, command_queue &queue, typename boost::enable_if< is_valid_fill_buffer_iterator<BufferIterator> >::type* = 0) { typedef typename std::iterator_traits<BufferIterator>::value_type value_type; // check if the device supports OpenCL 1.2 (required for enqueue_fill_buffer) if(!queue.check_device_version(1, 2)){ return fill_async_with_copy(first, count, value, queue); } value_type pattern = static_cast<value_type>(value); size_t offset = static_cast<size_t>(first.get_index()); event event_ = queue.enqueue_fill_buffer(first.get_buffer(), &pattern, sizeof(value_type), offset * sizeof(value_type), count * sizeof(value_type)); return future<void>(event_); }
ErrorCode LTSendBuffer::Frame::EncryptIfNeeded(LTSendBuffer & sendBuffer) { if (!shouldEncrypt_) { return ErrorCode(); } #ifdef PLATFORM_UNIX auto securityContext = sendBuffer.connection_->securityContext_.get(); Invariant(securityContext->TransportSecurity().SecurityProvider == SecurityProvider::Ssl); auto securityContextSsl = (SecurityContextSsl*)securityContext; //LINUXTODO avoid data copying during encryption auto reserveSize = sizeof(header_) + message_->SerializedBodySize(); ByteBuffer2 buffer(reserveSize); TcpConnection::WriteNoise( TraceType, sendBuffer.connection_->TraceId(), "Encrypt: {0}, plaintext length (including frame header) = {1}", message_->TraceId(), buffer.size()); buffer.append(&header_, sizeof(header_)); for (BufferIterator chunk = message_->BeginBodyChunks(); chunk != message_->EndBodyChunks(); ++chunk) { buffer.append(chunk->cbegin(), chunk->size()); } Invariant(buffer.size() == reserveSize); auto error = securityContextSsl->Encrypt(buffer.data(), buffer.size()); if (!error.IsSuccess()) return error; encrypted_ = securityContextSsl->EncryptFinal(); // adjust for size change due to encryption auto bufferedBefore = sendBuffer.totalBufferedBytes_; sendBuffer.totalBufferedBytes_ -= buffer.size(); sendBuffer.totalBufferedBytes_ += encrypted_.size(); TcpConnection::WriteNoise( TraceType, sendBuffer.connection_->TraceId(), "Encrypt: plain = {0}, encrypted = {1}, totalBufferedBytes_: before = {2}, after = {3}", buffer.size(), encrypted_.size(), bufferedBefore, sendBuffer.totalBufferedBytes_); return error; #else sendBuffer; Assert::CodingError("not implemented"); #endif }
inline void dispatch_fill(BufferIterator first, size_t count, const T &value, command_queue &queue, typename boost::enable_if< is_valid_fill_buffer_iterator<BufferIterator> >::type* = 0) { typedef typename std::iterator_traits<BufferIterator>::value_type value_type; if(count == 0){ // nothing to do return; } // check if the device supports OpenCL 1.2 (required for enqueue_fill_buffer) if(!queue.check_device_version(1, 2)){ return fill_with_copy(first, count, value, queue); } value_type pattern = static_cast<value_type>(value); size_t offset = static_cast<size_t>(first.get_index()); if(count == 1){ // use clEnqueueWriteBuffer() directly when writing a single value // to the device buffer. this is potentially more efficient and also // works around a bug in the intel opencl driver. queue.enqueue_write_buffer( first.get_buffer(), offset * sizeof(value_type), sizeof(value_type), &pattern ); } else { queue.enqueue_fill_buffer( first.get_buffer(), &pattern, sizeof(value_type), offset * sizeof(value_type), count * sizeof(value_type) ); } }
void dispatch_fill(BufferIterator first, size_t count, const T &value, command_queue &queue, typename boost::enable_if_c< is_buffer_iterator<BufferIterator>::value >::type* = 0) { typedef typename std::iterator_traits<BufferIterator>::value_type value_type; value_type pattern = static_cast<value_type>(value); size_t offset = static_cast<size_t>(first.get_index()); queue.enqueue_fill_buffer(first.get_buffer(), &pattern, sizeof(value_type), offset * sizeof(value_type), count * sizeof(value_type)); }
inline future<void> dispatch_fill_async(BufferIterator first, size_t count, const T &value, command_queue &queue, typename boost::enable_if< is_valid_fill_buffer_iterator<BufferIterator> >::type* = 0) { typedef typename std::iterator_traits<BufferIterator>::value_type value_type; value_type pattern = static_cast<value_type>(value); size_t offset = static_cast<size_t>(first.get_index()); event event_ = queue.enqueue_fill_buffer(first.get_buffer(), &pattern, sizeof(value_type), offset * sizeof(value_type), count * sizeof(value_type)); return future<void>(event_); }
ErrorCode LTSendBuffer::Frame::PrepareForSending(LTSendBuffer & sendBuffer) { Invariant(!preparedForSending_); preparedForSending_ = true; ErrorCode error = EncryptIfNeeded(sendBuffer); if (!error.IsSuccess()) { return error; } if (!encrypted_.empty()) { Invariant(shouldEncrypt_); sendBuffer.preparedBuffers_.emplace_back(ConstBuffer(encrypted_.data(), encrypted_.size())); sendBuffer.sendingLength_ += encrypted_.size(); return error; } // add frame header if (message_->Actor != Actor::SecurityContext) { sendBuffer.preparedBuffers_.emplace_back(ConstBuffer(&header_, sizeof(header_))); sendBuffer.sendingLength_ += sizeof(header_); } // add message body for (BufferIterator chunk = message_->BeginBodyChunks(); chunk != message_->EndBodyChunks(); ++chunk) { if (chunk->size() == 0) continue; sendBuffer.preparedBuffers_.emplace_back(ConstBuffer(chunk->cbegin(), chunk->size())); sendBuffer.sendingLength_ += chunk->size(); } return error; }