Ejemplo n.º 1
0
	/**
	\brief Converts from multiple to different precision multiple precision

	Changes the precision of the internal temporaries to desired precision

	\param new_precision The new precision.
	*/
	void MultipleToDouble() const
	{
		mpfr_float::default_precision(DoublePrecision());
		precision_ = DoublePrecision();

		ChangeTemporariesPrecision(DoublePrecision());

		MultipleToDoubleImpl();
	}
Ejemplo n.º 2
0
	/**
	Change precision of endgame object to next_precision.  Converts the internal temporaries, and adjusts precision of system. 

	\param new_precision The precision to change to.
	\return SuccessCode indicating whether the change was successful.  If the precision increases, and the refinement loop fails, this could be not Success.  Changing down is guaranteed to succeed.
	*/
	SuccessCode ChangePrecision(unsigned new_precision) const
	{
		if (new_precision==precision_) // no op
			return SuccessCode::Success;

		if (new_precision==DoublePrecision() && precision_>DoublePrecision())
			MultipleToDouble();
		else if(new_precision > DoublePrecision() && precision_ == DoublePrecision())
			DoubleToMultiple(new_precision);
		else
			MultipleToMultiple(new_precision);


		#ifndef BERTINI_DISABLE_ASSERTS
		assert(PrecisionSanityCheck() && "precision sanity check failed.  some internal variable is not in correct precision");
		#endif

		return SuccessCode::Success;
	}
Ejemplo n.º 3
0
void gemm(const DynamicView& result, double beta,
    const ConstDynamicView& left,  bool transposeLeft, double alpha,
    const ConstDynamicView& right, bool transposeRight)
{
    assert(left.size().size() == right.size().size());
    assert(left.size().size() == result.size().size());
    assert(left.size().size() == 2);

    assert(left.precision() == right.precision());
    assert(left.precision() == result.precision());

    size_t m = transposeLeft  ? left.size()[1]  : left.size()[0];
    size_t n = transposeRight ? right.size()[0] : right.size()[1];
    size_t k = transposeLeft  ? left.size()[0]  : left.size()[1];

    assert(k == (transposeRight ? right.size()[1] : right.size()[0]));

    size_t lda = left.stride()[1];
    size_t ldb = right.stride()[1];
    size_t ldc = result.stride()[1];

    if(CublasLibrary::loaded())
    {
        parallel::setNotSynchronized();

        if(left.precision() == SinglePrecision())
        {
            float alphaCopy = alpha;
            float betaCopy  = beta;
            CublasLibrary::cublasSgemm(transposeLeft ?
                CublasLibrary::CUBLAS_OP_T : CublasLibrary::CUBLAS_OP_N,
                transposeRight ? CublasLibrary::CUBLAS_OP_T : CublasLibrary::CUBLAS_OP_N,
                m, n, k, &alphaCopy,
                left.data<float>(),   lda,
                right.data<float>(),  ldb, &betaCopy,
                result.data<float>(), ldc);
        }
        else if(left.precision() == DoublePrecision())
        {
            CublasLibrary::cublasDgemm(transposeLeft ?
                CublasLibrary::CUBLAS_OP_T : CublasLibrary::CUBLAS_OP_N,
                transposeRight ? CublasLibrary::CUBLAS_OP_T : CublasLibrary::CUBLAS_OP_N,
                m, n, k, &alpha,
                left.data<double>(),   lda,
                right.data<double>(),  ldb, &beta,
                result.data<double>(), ldc);
        }
        else
        {
            throw std::runtime_error("Precision not implemented.");
        }
    }
    else if(AtlasLibrary::loaded())
    {
        if(left.precision() == SinglePrecision())
        {
            AtlasLibrary::sgemm(AtlasLibrary::CblasColMajor,
                transposeLeft  ? AtlasLibrary::CblasTrans : AtlasLibrary::CblasNoTrans,
                transposeRight ? AtlasLibrary::CblasTrans : AtlasLibrary::CblasNoTrans,
                m, n, k, alpha,
                left.data<float>(),   lda,
                right.data<float>(),  ldb, beta,
                result.data<float>(), ldc);
        }
        else if(left.precision() == DoublePrecision())
        {
            AtlasLibrary::dgemm(AtlasLibrary::CblasColMajor,
                transposeLeft  ? AtlasLibrary::CblasTrans : AtlasLibrary::CblasNoTrans,
                transposeRight ? AtlasLibrary::CblasTrans : AtlasLibrary::CblasNoTrans,
                m, n, k, alpha,
                left.data<double>(),   lda,
                right.data<double>(),  ldb, beta,
                result.data<double>(), ldc);
        }
        else
        {
            throw std::runtime_error("Precision not implemented.");
        }
    }
    else
    {
        throw std::runtime_error("Fallback GEMM not implemented.");
    }
}