Ejemplo n.º 1
0
std::vector<std::pair<void*, long> > DaxpyKernel::getBuffers() {
	std::vector<std::pair<void*, long> > result;
	result.push_back(std::make_pair(x,getVectorSize()*sizeof(double)));
	result.push_back(std::make_pair(y,getVectorSize()*sizeof(double)));
	return result;

}
Ejemplo n.º 2
0
 void DspDac::perform() noexcept
 {
     for(vector<float*>::size_type i = 0; i < m_outputs.size(); i++)
     {
         Signal::vadd(getVectorSize(), getInputsSamples()[i], m_outputs[i]);
     }
 }
void SpiralSKernel::initialize() {
	//BlasKernelBase::initialize();

	// seed random number generator for reproduceability
	srand48(0);

	long size=getVectorSize();

	// allocate memory
	if (posix_memalign((void**) (&x), 4*1024, size* sizeof(double)) != 0) {
			throw "could not allocate memory";
		}
        if (posix_memalign((void**) (&y), 4*1024, size* sizeof(double)) != 0) {
                        throw "could not allocate memory";
                }
	dummy.input = x;
	dummy.output = y;
	// initialize factors
	alpha=drand48();

	// initialize vectors
	for (long i=0; i<size; i++){
		x[i]=drand48();
	}



}
Ejemplo n.º 4
0
	//! return the n-th vector's element
	int TupleVectorNode::getImmediateValue(unsigned index) const
	{
		assert(index < getVectorSize());
		assert(isImmediateVector());
		ImmediateNode* node = dynamic_cast<ImmediateNode*>(children[index]);
		assert(node);
		return node->value;
	}
Ejemplo n.º 5
0
void DaxpyKernel::run() {
	cblas_daxpy(getVectorSize(), alpha, x, 1, y, 1);

	/*
	 void cblas_daxpy(const MKL_INT N, const double alpha, const double *X,
	 const MKL_INT incX, double *Y, const MKL_INT incY);
	 */
}
Ejemplo n.º 6
0
void broadcast(Vector* threads, struct Message msg) {
    mprintf("Broadcasting message with type %d\n", msg.type);
    size_t len = getVectorSize(threads);
    for (size_t i = 0; i < len; i++) {
        struct PlaneThread* plane = (struct PlaneThread*) getFromVector(threads, i);
        if (!plane->done) {
            message_queue_push(plane->queue, msg);
        }
    }
}
Ejemplo n.º 7
0
int getProductId(char* productName, Vector* products) {

    size_t len = getVectorSize(products);
    for (size_t i =0; i < len; i++) {
        Product* product = (Product*) getFromVector(products, i);
        if (strcmp(productName, product->name) ==0){
            return product->id;
        }
    }

    return -1;
}
Ejemplo n.º 8
0
// =============================================================================
Epetra_NumPyMultiVector::Epetra_NumPyMultiVector(PyObject * pyObject):
  Epetra_MultiVector(View, getMap(pyObject), getArray(pyObject),
		     getVectorSize(pyObject), getNumVectors(pyObject))
{
  // Store the pointer to the Epetra_Map
  map     = tmp_map;
  tmp_map = NULL;

  // Store the pointer to the PyArrayObject
  array     = tmp_array;
  tmp_array = NULL;
}
std::set< std::string > MatLabEngine::getMxFieldNames( const std::string &mxVarName ) {
	std::string command = "ans = []";
	executeCommand( command );

	int size = getMxLinearSize( mxVarName );
	if ( size == 0 ) {
		return std::set< std::string >();
	}

	command = std::string( "fieldnames( " ) + mxVarName + " )";
//std::cerr << "getMxFieldNames: \"" << command << "\"" << std::endl;
	executeCommand( command, true );

	std::set< std::string > retval;

	mxArray *mxCellArray;
	if (   (  mxCellArray = engGetVariable( _ep, "ans" )  )  !=  0   ) {

		int mxCellArraySize = getVectorSize(  mxGetDimensions( mxCellArray )  );

		for( int ix = 0 ; ix < mxCellArraySize ; ++ix ) {
			mxArray *mxCell = mxGetCell( mxCellArray, ix );

			int stringLength = getVectorSize(  mxGetDimensions( mxCell )  );
#ifdef _WIN32
			wchar_t *stringValue  = static_cast< wchar_t * >(  mxGetData( mxCell )  );
#else
			short *stringValue  = static_cast< short * >(  mxGetData( mxCell )  );
#endif
			retval.insert(  std::string( stringValue, stringValue + stringLength )  );

		}

		mxDestroyArray( mxCellArray );
	}

	return retval;
}
Ejemplo n.º 10
0
int MatLabEngine::getMxLinearSize( const std::string &mxVarName, const bool unchecked ) {
	executeCommand( "ans = 0" );
	std::string command = std::string( "size( " ) + mxVarName + " )";
//std::cerr << "getMxLinearSize: \"" << command << "\"" << std::endl;
	executeCommand( command, unchecked );
	mxArray *mxSizeArray;
	if (   (  mxSizeArray = engGetVariable( _ep, "ans" )  )  ==  0   ) {
		throw MatLabUdm::Exception( std::string( "Could not get size of array " ) + mxVarName );
	}

	int retval = getVectorSize( mxSizeArray );
	mxDestroyArray( mxSizeArray );

	return retval;
}
Ejemplo n.º 11
0
std::string MatLabEngine::getMxStringValue( const std::string &mxVarName, const bool unchecked ) {
	executeCommand( "ans = ''" );
//std::cerr << "getMxStringValue: \"" << mxVarName << "\"" << std::endl;
	executeCommand( mxVarName, unchecked );
	mxArray *mxStringArray;
	std::string retval("");

	if (   (  mxStringArray = engGetVariable( _ep, "ans" )  )  !=  0   ) {
		int stringLength = getVectorSize(  mxGetDimensions( mxStringArray )  );
#ifdef _WIN32
		wchar_t *stringValue  = static_cast< wchar_t * >(  mxGetData( mxStringArray )  );
#else
		short *stringValue  = static_cast< short * >(  mxGetData( mxStringArray )  );
#endif
		retval.assign( stringValue, stringValue + stringLength );
		mxDestroyArray( mxStringArray );
	}

	return retval;
}
Ejemplo n.º 12
0
void start_phase(Vector* threads, struct Message msg) {

    pthread_mutex_lock(&planesLeftLock);
    size_t len = getVectorSize(threads);
    planesLeftInStage = 0;
    for (size_t i = 0; i < len; i++) {
        struct PlaneThread* thread = (struct PlaneThread*) getFromVector(threads, i);
        if (!thread->done) {
            planesLeftInStage++;
        }
    }
    mprintf("Setting planes left to %d\n", planesLeftInStage);

    if (planesLeftInStage == 0) {
        send_ready_message();
    } else {
        broadcast(threads, msg);
    }
    pthread_mutex_unlock(&planesLeftLock);
}
Ejemplo n.º 13
0
	//! Expand to memory[index]
	Node* MemoryVectorNode::expandVectorialNodes(std::wostream *dump, Compiler* compiler, unsigned int index)
	{
		assert(index < getVectorSize());

		// get the optional index given in the Aseba code
		TupleVectorNode* accessIndex = NULL;
		if (children.size() > 0)
			accessIndex = dynamic_cast<TupleVectorNode*>(children[0]);

		if (accessIndex || children.size() == 0)
		{
			// direct access. Several cases:
			// -> an immediate index "foo[n]" or "foo[n:m]"
			// -> full array access "foo"
			// => use a StoreNode (lvalue) or LoadNode (rvalue)

			unsigned pointer = getVectorAddr() + index;
			// check if index is within bounds
			if (pointer >= arrayAddr + arraySize)
				throw TranslatableError(sourcePos, ERROR_ARRAY_OUT_OF_BOUND).arg(arrayName).arg(index).arg(arraySize);

			if (write == true)
				return new StoreNode(sourcePos, pointer);
			else
				return new LoadNode(sourcePos, pointer);
		}
		else
		{
			// indirect access foo[expr]
			// => use a ArrayWriteNode (lvalue) or ArrayReadNode (rvalue)

			std::auto_ptr<Node> array;
			if (write == true)
				array.reset(new ArrayWriteNode(sourcePos, arrayAddr, arraySize, arrayName));
			else
				array.reset(new ArrayReadNode(sourcePos, arrayAddr, arraySize, arrayName));

			array->children.push_back(children[0]->expandVectorialNodes(dump, compiler, index));
			return array.release();
		}
	}
Ejemplo n.º 14
0
//
// Recursively generate mangled names.
//
void TType::buildMangledName(TString& mangledName) const
{
    if (isMatrix())
        mangledName += 'm';
    else if (isVector())
        mangledName += 'v';

    switch (basicType) {
    case EbtFloat:              mangledName += 'f';      break;
    case EbtDouble:             mangledName += 'd';      break;
#ifdef AMD_EXTENSIONS
    case EbtFloat16:            mangledName += "f16";    break;
#endif
    case EbtInt:                mangledName += 'i';      break;
    case EbtUint:               mangledName += 'u';      break;
    case EbtInt64:              mangledName += "i64";    break;
    case EbtUint64:             mangledName += "u64";    break;
#ifdef AMD_EXTENSIONS
    case EbtInt16:              mangledName += "i16";    break;
    case EbtUint16:             mangledName += "u16";    break;
#endif
    case EbtBool:               mangledName += 'b';      break;
    case EbtAtomicUint:         mangledName += "au";     break;
    case EbtSampler:
        switch (sampler.type) {
        case EbtInt:   mangledName += "i"; break;
        case EbtUint:  mangledName += "u"; break;
        default: break; // some compilers want this
        }
        if (sampler.image)
            mangledName += "I";  // a normal image
        else if (sampler.sampler)
            mangledName += "p";  // a "pure" sampler
        else if (!sampler.combined)
            mangledName += "t";  // a "pure" texture
        else
            mangledName += "s";  // traditional combined sampler
        if (sampler.arrayed)
            mangledName += "A";
        if (sampler.shadow)
            mangledName += "S";
        if (sampler.external)
            mangledName += "E";
        switch (sampler.dim) {
        case Esd1D:       mangledName += "1";  break;
        case Esd2D:       mangledName += "2";  break;
        case Esd3D:       mangledName += "3";  break;
        case EsdCube:     mangledName += "C";  break;
        case EsdRect:     mangledName += "R2"; break;
        case EsdBuffer:   mangledName += "B";  break;
        case EsdSubpass:  mangledName += "P";  break;
        default: break; // some compilers want this
        }

        switch (sampler.vectorSize) {
        case 1: mangledName += "1"; break;
        case 2: mangledName += "2"; break;
        case 3: mangledName += "3"; break;
        case 4: break; // default to prior name mangle behavior
        }

        if (sampler.ms)
            mangledName += "M";
        break;
    case EbtStruct:
    case EbtBlock:
        if (basicType == EbtStruct)
            mangledName += "struct-";
        else
            mangledName += "block-";
        if (typeName)
            mangledName += *typeName;
        for (unsigned int i = 0; i < structure->size(); ++i) {
            mangledName += '-';
            (*structure)[i].type->buildMangledName(mangledName);
        }
    default:
        break;
    }

    if (getVectorSize() > 0)
        mangledName += static_cast<char>('0' + getVectorSize());
    else {
        mangledName += static_cast<char>('0' + getMatrixCols());
        mangledName += static_cast<char>('0' + getMatrixRows());
    }

    if (arraySizes) {
        const int maxSize = 11;
        char buf[maxSize];
        for (int i = 0; i < arraySizes->getNumDims(); ++i) {
            if (arraySizes->getDimNode(i)) {
                if (arraySizes->getDimNode(i)->getAsSymbolNode())
                    snprintf(buf, maxSize, "s%d", arraySizes->getDimNode(i)->getAsSymbolNode()->getId());
                else
                    snprintf(buf, maxSize, "s%p", arraySizes->getDimNode(i));
            } else
                snprintf(buf, maxSize, "%d", arraySizes->getDimSize(i));
            mangledName += '[';
            mangledName += buf;
            mangledName += ']';
        }
    }
}
// =============================================================================
Epetra_NumPySerialDenseVector::Epetra_NumPySerialDenseVector(PyObject * pyObject) :
  Epetra_SerialDenseVector(View, getArray(pyObject), getVectorSize(pyObject))
{
  // Synchronize the PyArrayObject with the Epetra_SerialDenseVector
  setArray();
}
Ejemplo n.º 16
0
//
// Recursively generate mangled names.
//
void TType::buildMangledName(TString& mangledName)
{
    if (isMatrix())
        mangledName += 'm';
    else if (isVector())
        mangledName += 'v';

    switch (basicType) {
    case EbtFloat:              mangledName += 'f';      break;
    case EbtDouble:             mangledName += 'd';      break;
    case EbtInt:                mangledName += 'i';      break;
    case EbtUint:               mangledName += 'u';      break;
    case EbtBool:               mangledName += 'b';      break;
    case EbtSampler:
        switch (sampler.type) {
        case EbtInt:   mangledName += "i"; break;
        case EbtUint:  mangledName += "u"; break;
        default: break; // some compilers want this
        }
        if (sampler.image)
            mangledName += "I";
        else
            mangledName += "s";
        if (sampler.arrayed)
            mangledName += "A";
        if (sampler.shadow)
            mangledName += "S";
        switch (sampler.dim) {
        case Esd1D:       mangledName += "1";  break;
        case Esd2D:       mangledName += "2";  break;
        case Esd3D:       mangledName += "3";  break;
        case EsdCube:     mangledName += "C";  break;
        case EsdRect:     mangledName += "R2"; break;
        case EsdBuffer:   mangledName += "B";  break;
        default: break; // some compilers want this
        }
        break;
    case EbtStruct:
        mangledName += "struct-";
        if (typeName)
            mangledName += *typeName;
        for (unsigned int i = 0; i < structure->size(); ++i) {
            mangledName += '-';
            (*structure)[i].type->buildMangledName(mangledName);
        }
    default:
        break;
    }

    if (getVectorSize() > 0)
        mangledName += static_cast<char>('0' + getVectorSize());
    else {
        mangledName += static_cast<char>('0' + getMatrixCols());
        mangledName += static_cast<char>('0' + getMatrixRows());
    }

    if (arraySizes) {
        const int maxSize = 11;
        char buf[maxSize];
        snprintf(buf, maxSize, "%d", arraySizes->sizes.front());
        mangledName += '[';
        mangledName += buf;
        mangledName += ']';
    }
}
Ejemplo n.º 17
0
	std::wstring TupleVectorNode::toWString() const
	{
		return WFormatableString(L"Tuple Vector: size %0").arg(getVectorSize());
	}
Ejemplo n.º 18
0
//
// Do folding between a pair of nodes
//
TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNode)
{
    TConstUnion *unionArray = getUnionArrayPointer();
    int objectSize = getType().getObjectSize();
    TConstUnion* newConstArray = 0;

    // For most cases, the return type matches the argument type, so set that
    // up and just code to exceptions below.
    TType returnType;
    returnType.shallowCopy(getType());

    //
    // A pair of nodes is to be folded together
    //

    TIntermConstantUnion *node = constantNode->getAsConstantUnion();
    TConstUnion *rightUnionArray = node->getUnionArrayPointer();

    if (constantNode->getType().getObjectSize() == 1 && objectSize > 1) {
        // for a case like float f = vec4(2,3,4,5) + 1.2;
        rightUnionArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; ++i)
            rightUnionArray[i] = *node->getUnionArrayPointer();
    } else if (constantNode->getType().getObjectSize() > 1 && objectSize == 1) {
        // for a case like float f = 1.2 + vec4(2,3,4,5);
        rightUnionArray = node->getUnionArrayPointer();
        unionArray = new TConstUnion[constantNode->getType().getObjectSize()];
        for (int i = 0; i < constantNode->getType().getObjectSize(); ++i)
            unionArray[i] = *getUnionArrayPointer();
        returnType.shallowCopy(node->getType());
        objectSize = constantNode->getType().getObjectSize();
    }

    int index = 0;
    bool boolNodeFlag = false;
    switch(op) {
    case EOpAdd:
        newConstArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; i++)
            newConstArray[i] = unionArray[i] + rightUnionArray[i];
        break;
    case EOpSub:
        newConstArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; i++)
            newConstArray[i] = unionArray[i] - rightUnionArray[i];
        break;

    case EOpMul:
    case EOpVectorTimesScalar:
    case EOpMatrixTimesScalar:
        newConstArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; i++)
            newConstArray[i] = unionArray[i] * rightUnionArray[i];
        break;
    case EOpMatrixTimesMatrix:
        newConstArray = new TConstUnion[getMatrixRows() * node->getMatrixCols()];
        for (int row = 0; row < getMatrixRows(); row++) {
            for (int column = 0; column < node->getMatrixCols(); column++) {
                double sum = 0.0f;
                for (int i = 0; i < node->getMatrixRows(); i++)
                    sum += unionArray[i * getMatrixRows() + row].getDConst() * rightUnionArray[column * node->getMatrixRows() + i].getDConst();
                newConstArray[column * getMatrixRows() + row].setDConst(sum);
            }
        }
        returnType.shallowCopy(TType(getType().getBasicType(), EvqConst, 0, getMatrixRows(), node->getMatrixCols()));
        break;
    case EOpDiv:
        newConstArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; i++) {
            switch (getType().getBasicType()) {
            case EbtDouble:
            case EbtFloat:
                newConstArray[i].setDConst(unionArray[i].getDConst() / rightUnionArray[i].getDConst());
                break;

            case EbtInt:
                if (rightUnionArray[i] == 0) {
                    newConstArray[i].setIConst(0xEFFFFFFF);
                } else
                    newConstArray[i].setIConst(unionArray[i].getIConst() / rightUnionArray[i].getIConst());
                break;

            case EbtUint:
                if (rightUnionArray[i] == 0) {
                    newConstArray[i].setUConst(0xFFFFFFFF);
                } else
                    newConstArray[i].setUConst(unionArray[i].getUConst() / rightUnionArray[i].getUConst());
                break;
            default:
                return 0;
            }
        }
        break;

    case EOpMatrixTimesVector:
        newConstArray = new TConstUnion[getMatrixRows()];
        for (int i = 0; i < getMatrixRows(); i++) {
            double sum = 0.0f;
            for (int j = 0; j < node->getVectorSize(); j++) {
                sum += unionArray[j*getMatrixRows() + i].getDConst() * rightUnionArray[j].getDConst();
            }
            newConstArray[i].setDConst(sum);
        }

        returnType.shallowCopy(TType(getBasicType(), EvqConst, getMatrixRows()));
        break;

    case EOpVectorTimesMatrix:
        newConstArray = new TConstUnion[node->getMatrixCols()];
        for (int i = 0; i < node->getMatrixCols(); i++) {
            double sum = 0.0f;
            for (int j = 0; j < getVectorSize(); j++)
                sum += unionArray[j].getDConst() * rightUnionArray[i*node->getMatrixRows() + j].getDConst();
            newConstArray[i].setDConst(sum);
        }

        returnType.shallowCopy(TType(getBasicType(), EvqConst, node->getMatrixCols()));
        break;

    case EOpMod:
        newConstArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; i++)
            newConstArray[i] = unionArray[i] % rightUnionArray[i];
        break;

    case EOpRightShift:
        newConstArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; i++)
            newConstArray[i] = unionArray[i] >> rightUnionArray[i];
        break;

    case EOpLeftShift:
        newConstArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; i++)
            newConstArray[i] = unionArray[i] << rightUnionArray[i];
        break;

    case EOpAnd:
        newConstArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; i++)
            newConstArray[i] = unionArray[i] & rightUnionArray[i];
        break;
    case EOpInclusiveOr:
        newConstArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; i++)
            newConstArray[i] = unionArray[i] | rightUnionArray[i];
        break;
    case EOpExclusiveOr:
        newConstArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; i++)
            newConstArray[i] = unionArray[i] ^ rightUnionArray[i];
        break;

    case EOpLogicalAnd: // this code is written for possible future use, will not get executed currently
        newConstArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; i++)
            newConstArray[i] = unionArray[i] && rightUnionArray[i];
        break;

    case EOpLogicalOr: // this code is written for possible future use, will not get executed currently
        newConstArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; i++)
            newConstArray[i] = unionArray[i] || rightUnionArray[i];
        break;

    case EOpLogicalXor:
        newConstArray = new TConstUnion[objectSize];
        for (int i = 0; i < objectSize; i++) {
            switch (getType().getBasicType()) {
            case EbtBool: newConstArray[i].setBConst((unionArray[i] == rightUnionArray[i]) ? false : true); break;
            default: assert(false && "Default missing");
            }
        }
        break;

    case EOpLessThan:
        assert(objectSize == 1);
        newConstArray = new TConstUnion[1];
        newConstArray->setBConst(*unionArray < *rightUnionArray);
        returnType.shallowCopy(TType(EbtBool, EvqConst));
        break;
    case EOpGreaterThan:
        assert(objectSize == 1);
        newConstArray = new TConstUnion[1];
        newConstArray->setBConst(*unionArray > *rightUnionArray);
        returnType.shallowCopy(TType(EbtBool, EvqConst));
        break;
    case EOpLessThanEqual:
    {
        assert(objectSize == 1);
        TConstUnion constant;
        constant.setBConst(*unionArray > *rightUnionArray);
        newConstArray = new TConstUnion[1];
        newConstArray->setBConst(!constant.getBConst());
        returnType.shallowCopy(TType(EbtBool, EvqConst));
        break;
    }
    case EOpGreaterThanEqual:
    {
        assert(objectSize == 1);
        TConstUnion constant;
        constant.setBConst(*unionArray < *rightUnionArray);
        newConstArray = new TConstUnion[1];
        newConstArray->setBConst(!constant.getBConst());
        returnType.shallowCopy(TType(EbtBool, EvqConst));
        break;
    }

    case EOpEqual:
        if (getType().getBasicType() == EbtStruct) {
            if (! CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
                boolNodeFlag = true;
        } else {
            for (int i = 0; i < objectSize; i++) {
                if (unionArray[i] != rightUnionArray[i]) {
                    boolNodeFlag = true;
                    break;  // break out of for loop
                }
            }
        }

        newConstArray = new TConstUnion[1];
        newConstArray->setBConst(! boolNodeFlag);
        returnType.shallowCopy(TType(EbtBool, EvqConst));
        break;

    case EOpNotEqual:
        if (getType().getBasicType() == EbtStruct) {
            if (CompareStructure(node->getType(), node->getUnionArrayPointer(), unionArray))
                boolNodeFlag = true;
        } else {
            for (int i = 0; i < objectSize; i++) {
                if (unionArray[i] == rightUnionArray[i]) {
                    boolNodeFlag = true;
                    break;  // break out of for loop
                }
            }
        }

        newConstArray = new TConstUnion[1];
        newConstArray->setBConst(! boolNodeFlag);
        returnType.shallowCopy(TType(EbtBool, EvqConst));
        break;

    default:
        return 0;
    }

    TIntermConstantUnion *newNode = new TIntermConstantUnion(newConstArray, returnType);
    newNode->setLoc(getLoc());

    return newNode;
}