VectorMatrixCU64Accessor::VectorMatrixCU64Accessor(VectorMatrix &mat) : mat(mat)
{
    mat.writeLock(2); // 2 = CU64Device!
    data_x = static_cast<CU64Array*>(mat.getArray(2, 0))->ptr();
    data_y = static_cast<CU64Array*>(mat.getArray(2, 1))->ptr();
    data_z = static_cast<CU64Array*>(mat.getArray(2, 2))->ptr();
}
ConstVectorMatrixCU64Accessor::ConstVectorMatrixCU64Accessor(const VectorMatrix &mat) : mat(mat)
{
    mat.readLock(2);
    data_x = static_cast<CU64Array*>(mat.getArray(2, 0))->ptr();
    data_y = static_cast<CU64Array*>(mat.getArray(2, 1))->ptr();
    data_z = static_cast<CU64Array*>(mat.getArray(2, 2))->ptr();
}
VectorMatrixCU32Accessor::VectorMatrixCU32Accessor(VectorMatrix &mat) : mat(mat)
{
    mat.writeLock(1); // 1 = CU32Device!
    data_x = static_cast<CU32Array*>(mat.getArray(1, 0))->ptr();
    data_y = static_cast<CU32Array*>(mat.getArray(1, 1))->ptr();
    data_z = static_cast<CU32Array*>(mat.getArray(1, 2))->ptr();
}
ConstVectorMatrixAccessor::ConstVectorMatrixAccessor(const VectorMatrix &mat) : mat(mat) 
{
	mat.readLock(0);
	data_x = static_cast<CPUArray*>(mat.getArray(0, 0))->ptr();
	data_y = static_cast<CPUArray*>(mat.getArray(0, 1))->ptr();
	data_z = static_cast<CPUArray*>(mat.getArray(0, 2))->ptr();

	// Precalculate strides
	const int rank = mat.getShape().getRank();
	strides[0] = 1;
	strides[1] = strides[0] * (rank > 0 ? mat.getShape().getDim(0) : 1);
	strides[2] = strides[1] * (rank > 1 ? mat.getShape().getDim(1) : 1);
	strides[3] = strides[2] * (rank > 2 ? mat.getShape().getDim(2) : 1);
}
Exemplo n.º 5
0
double VectorMatrix::dotSum(const VectorMatrix &other) const
{
	if (isUniform() && other.isUniform()) {
		const double x = uval[0], y = uval[1], z = uval[2];
		const double dot = x*x + y*y + z*z;
		return size() * dot;
	} else {
		const int dev = computeStrategy2(other);
		readLock(dev); if (this != &other) other.readLock(dev);
		const double sum = matty::getDevice(dev)->sumdot3(
			this->getArray(dev, 0), this->getArray(dev, 1), this->getArray(dev, 2),
			other.getArray(dev, 0), other.getArray(dev, 1), other.getArray(dev, 2)
		);
		if (this != &other) other.readUnlock(dev); readUnlock(dev);
		return sum;
	}
}
Exemplo n.º 6
0
void VectorMatrix::assign(const VectorMatrix &op)
{
	if (this == &op) {
		return;
	} else if (op.isUniform()) {
		fill(op.getUniformValue());
	} else {
		const int dev = computeStrategy2(op);
		writeLock(dev); op.readLock(dev);
		for (int c=0; c<num_arrays; ++c) {
			matty::getDevice(dev)->assign(getArray(dev, c), op.getArray(dev, c));
		}
		writeUnlock(dev); op.readUnlock(dev);
	}
}
Exemplo n.º 7
0
void VectorMatrix::add(const VectorMatrix &op, double factor)
{
	if (this == &op) {
		scale(1.0 + factor);
	} else if (isUniform() && op.isUniform()) {
		fill(getUniformValue() + op.getUniformValue() * factor);
	} else {
		const int dev = computeStrategy2(op);
		writeLock(dev); op.readLock(dev);
		for (int c=0; c<num_arrays; ++c) {
			matty::getDevice(dev)->add(getArray(dev, c), op.getArray(dev, c), factor);
		}
		writeUnlock(dev); op.readUnlock(dev);
	}
}