Ejemplo n.º 1
0
Tensor Tensor::reshape(const char* data, const std::vector<int>& shape, bool alloc, Format fmt)
{
    if (device_ == VK_NULL_HANDLE)
    {
        CV_Error(Error::StsError, "device is NULL");
        return *this;
    }

    CV_Assert(shape.size() > 0 && shape.size() <= 6);

    if (shape_ != shape) shape_ = shape;
    if (checkFormat(fmt) && fmt != format_) format_ = fmt;

    size_t new_size = shapeCount(shape_) * elementSize(format_);
    if (alloc || new_size > size_in_byte_)
        alloc = true;
    size_in_byte_ = new_size;

    if (alloc)
    {
        buffer_.reset(new Buffer(device_, size_in_byte_, data));
    }
    else if (data)
    {
        void* p = map();
        memcpy(p, data, size_in_byte_);
        unMap();
    }

    return *this;
}
Ejemplo n.º 2
0
	void FloatAttributeUpdater::prepareDraw()
	{
		unMap();
		
		if (m_uploads > 0 && m_data.size())
		{
			m_firstUpdated = std::min(m_firstUpdated,m_data.size() / getFloatsPerItem() - 1);
			m_lastUpdated  = std::min(m_lastUpdated ,m_data.size() / getFloatsPerItem() - 1);
			
			fm::Size elemCount = m_lastUpdated - m_firstUpdated + 1;
/*
			float ratio = elemCount / float(m_data.size() / getFloatsPerItem());
			if (ratio > 0.3)
			{
				m_attrib.buf->setData(nullptr,m_data.size() * sizeof(m_data[0]));
				m_attrib.buf->updateData((void*)&m_data[0],m_data.size() * sizeof(m_data[0]));
			}
			else*/
			{
				m_attrib.buf->updateData((void*)&m_data[m_firstUpdated*getFloatsPerItem()],
										getBytesPerItem() * elemCount,
										getBytesPerItem() * m_firstUpdated);
			}
			m_uploads = 0;
		}
	}
Ejemplo n.º 3
0
	void FloatAttributeUpdater::clear()
	{
		unMap();
		
		m_firstUpdated = 0;
		m_lastUpdated = 0;
		m_capacity = 0;
		m_uploads = 0;
		m_data.clear();
		
		if (m_attrib.ownBuffer) delete m_attrib.buf;
		m_attrib.buf = nullptr;
		m_attrib.ownBuffer = false;
	}
Ejemplo n.º 4
0
void Tensor::setTo(float val)
{
    if (device_ == VK_NULL_HANDLE)
    {
        CV_Error(Error::StsError, "device is NULL");
        return;
    }

    CV_Assert(format_ == kFormatFp32);

    float* p = (float *)map();
    int cnt = count();
    for (int i = 0; i < cnt; i++)
        *p++ = val;
    unMap();
}
Ejemplo n.º 5
0
	void FloatAttributeUpdater::setCapacity(fm::Size capacity)
	{
		unMap();
		m_uploads = 0;
		
		m_attrib.compCount = m_floatPerVec;
		m_attrib.compType  = fg::Is_GLDataType<float>::enumVal;
		m_attrib.count     = capacity;
		m_attrib.stride    = 0;
		
		if (!m_attrib.ownBuffer || !m_attrib.buf)
		{
			m_attrib.ownBuffer = true;
			m_attrib.buf = new fg::Buffer(fg::ArrayBuffer,fg::StreamDraw);
		}
		
		m_attrib.buf->setData<float>(nullptr,capacity * getFloatsPerItem());
		
		if (m_data.size())
			m_attrib.buf->updateData<float>(&m_data[0],m_data.size());
		
		m_capacity = capacity;
	}
Ejemplo n.º 6
0
void Tensor::copyTo(Tensor& dst)
{
    void* p = map();
    dst.reshape((const char*)p, shape_, format_);
    unMap();
}