static inline void* newAllocation(struct Allocator_pvt* context, unsigned long size, const char* fileName, int lineNum) { check(context); int64_t realSize = getRealSize(size); struct Allocator_FirstCtx* rootAlloc = Identity_check(context->rootAlloc); if (rootAlloc->spaceAvailable <= realSize) { failure(context, "Out of memory, limit exceeded", fileName, lineNum); } rootAlloc->spaceAvailable -= realSize; context->allocatedHere += realSize; struct Allocator_Allocation_pvt* alloc = rootAlloc->provider(rootAlloc->providerContext, NULL, realSize, &context->pub); if (alloc == NULL) { failure(context, "Out of memory, malloc() returned NULL", fileName, lineNum); } alloc->next = context->allocations; alloc->pub.size = realSize; alloc->pub.fileName = fileName; alloc->pub.lineNum = lineNum; context->allocations = alloc; setCanaries(alloc, context); return (void*) (alloc + 1); }
void assignExtendedQDPGaugeField(const int dim[4], QudaPrecision precision, const void* const src, void** const dst) { const int matrix_size = 18*getRealSize(precision); const int volume = getVolume(dim); int extended_dim[4]; for(int dir=0; dir<4; ++dir) extended_dim[dir] = dim[dir]+4; const int extended_volume = getVolume(extended_dim); const int half_dim0 = extended_dim[0]/2; const int half_extended_volume = extended_volume/2; for(int i=0; i<extended_volume; ++i){ int site_id = i; int odd_bit = 0; if(i >= half_extended_volume){ site_id -= half_extended_volume; odd_bit = 1; } int za = site_id/half_dim0; int x1h = site_id - za*half_dim0; int zb = za/extended_dim[1]; int x2 = za - zb*extended_dim[1]; int x4 = zb/extended_dim[2]; int x3 = zb - x4*extended_dim[2]; int x1odd = (x2 + x3 + x4 + odd_bit) & 1; int x1 = 2*x1h + x1odd; x1 = (x1 - 2 + dim[0]) % dim[0]; x2 = (x2 - 2 + dim[1]) % dim[1]; x3 = (x3 - 2 + dim[2]) % dim[2]; x4 = (x4 - 2 + dim[3]) % dim[3]; int full_index = (x4*dim[2]*dim[1]*dim[0] + x3*dim[1]*dim[0] + x2*dim[0] + x1)>>1; if(odd_bit){ full_index += volume/2; } for(int dir=0; dir<4; ++dir){ char* dst_ptr = (char*)dst[dir]; memcpy(dst_ptr + i*matrix_size, (char*)src + (full_index*4 + dir)*matrix_size, matrix_size); } // end loop over directions } // loop over the extended volume // see if it makes a difference return; } // assignExtendedQDPGaugeField
void InterfaceItem::update(unsigned millisElapsed) { if (!hidden) { // We build the model matrix by applying the position, rotation and size, in this order //GameApp *gameApp = GameApp::getInstance(); Vector2 windowSize = Naquadah::getWindowSize(); Vector2 renderSize = getRealSize(); if (renderSize.x >= 0) { Vector2 renderPos = getRealPosition(); float realPosX = renderPos.x + (renderSize.x / 2.0f); float realPosY = windowSize.y - renderPos.y - (renderSize.y / 2.0f); modelMatrix = Matrix4::Translation(Vector3(realPosX, realPosY, 0.0f)); modelMatrix = modelMatrix * Matrix4::Rotation(rotation, Vector3(0, 0, 1)); modelMatrix = modelMatrix * Matrix4::Scale(Vector3(renderSize.x / 2.0f, renderSize.y / 2.0f, 1.0)); } // For each child, we have to manually calculate its model matrix /*for (std::vector<InterfaceItem*>::iterator it = innerItems->begin(); it != innerItems->end(); ++it) { // We call the default update of the child item, because that can be different from the // default as well (*it)->update(millisElapsed); // We build the model matrix by applying the position, rotation and size, in this order Vector2 *childRenderSize = new Vector2((*it)->getSize()); Vector2 *childRenderPos = new Vector2((*it)->getPosition()); if ((*it)->getSize().x == SIZE_NO_RESIZE && (*it)->getTexture() != nullptr) { childRenderSize->x = (float) (*it)->getTexture()->getTextureWidth(); } if ((*it)->getSize().y == SIZE_NO_RESIZE && (*it)->getTexture() != nullptr) { childRenderSize->y = (float) (*it)->getTexture()->getTextureHeight(); } if ((*it)->getPosition().x == POSITION_CENTERED) { childRenderPos->x = (windowSize.x / 2.0f) - (childRenderSize->x / 2.0f); } if ((*it)->getPosition().y == POSITION_CENTERED) { childRenderPos->y = (windowSize.y / 2.0f) - (childRenderSize->y / 2.0f); } float childRealPosX = (childRenderPos->x + renderPos.x) + (childRenderSize->x / 2.0f); float childRealPosY = (windowSize.y - (childRenderPos->y + renderPos.y)) - (childRenderSize->y / 2.0f); Matrix4 childModelMatrix; // We calculate the child's model matrix again, making sure rotation works childModelMatrix = Matrix4::Translation(Vector3(realPosX, realPosY, 0.0f)); childModelMatrix = childModelMatrix * Matrix4::Rotation(rotation, Vector3(0, 0, 1)); childModelMatrix = childModelMatrix * Matrix4::Translation(Vector3(-realPosX, -realPosY, 0.0f)); childModelMatrix = childModelMatrix * Matrix4::Translation(Vector3(childRealPosX, childRealPosY, 0.0f)); childModelMatrix = childModelMatrix * Matrix4::Rotation((*it)->getRotation(), Vector3(0, 0, 1)); childModelMatrix = childModelMatrix * Matrix4::Scale(Vector3(childRenderSize->x / 2, childRenderSize->y / 2, 1.0f)); (*it)->setModelMatrix(childModelMatrix); delete childRenderSize; delete childRenderPos; }*/ } }
void allocateColorField(int volume, QudaPrecision prec, bool usePinnedMemory, void*& field) { const int realSize = getRealSize(prec); int siteSize = 18; if(usePinnedMemory){ cudaMallocHost((void**)&field, volume*siteSize*realSize); }else{ field = (void*)malloc(volume*siteSize*realSize); } if(field == NULL){ errorQuda("ERROR: allocateColorField failed\n"); } return; }
bool InterfaceItem::isMouseHovering(Vector2 &mousePos) { Vector2 realSize = getRealSize(); Vector2 realPos = Vector2(*position); //GameApp *gameApp = GameApp::getInstance(); if (realPos.x == POSITION_CENTERED) { //realPos.x = (gameApp->getWindowWidth() / 2.0f) - (realSize.x / 2.0f); } if (realPos.y == POSITION_CENTERED) { //realPos.y = (gameApp->getWindowHeight() / 2.0f) - (realSize.y / 2.0f); } if (mousePos.x >= realPos.x && mousePos.x <= (realPos.x + realSize.x)) { return mousePos.y >= realPos.y && mousePos.y <= (realPos.y + realSize.y); } return false; }
Vector2 InterfaceItem::getRealPosition() { Vector2 windowSize = Naquadah::getWindowSize(); Vector2 realSize = getRealSize(); Vector2 realPos = Vector2(*position); if (position->x == POSITION_CENTERED) { realPos.x = (windowSize.x / 2.0f) - (realSize.x / 2.0f); } if (position->y == POSITION_CENTERED) { realPos.y = (windowSize.y / 2.0f) - (realSize.y / 2.0f); } //realPos.x = realPos.x + (realSize.x / 2.0f); //realPos.y = windowHeight - realPos.y - (realSize.y / 2.0f); // Scale according to screen resolution //realPos.x = realPos.x * (windowWidth / 1920.0f); //realPos.y = realPos.y * (windowHeight / 1080.0f); return realPos; }
// update boundaries (pretty inefficient). void updateExtendedQDPBorders(const int dim[4], QudaPrecision precision, void** const qdp_field) { const int matrix_size = 18*getRealSize(precision); int extended_dim[4]; for(int dir=0; dir<4; ++dir) extended_dim[dir] = dim[dir]+4; const int extended_volume = getVolume(extended_dim); const int half_dim0 = extended_dim[0]/2; const int half_extended_volume = extended_volume/2; for(int i=0; i<extended_volume; ++i){ int site_id = i; int odd_bit = 0; if(i >= half_extended_volume){ site_id -= half_extended_volume; odd_bit = 1; } int za = site_id/half_dim0; int x1h = site_id - za*half_dim0; int zb = za/extended_dim[1]; int x2 = za - zb*extended_dim[1]; int x4 = zb/extended_dim[2]; int x3 = zb - x4*extended_dim[2]; int x1odd = (x2 + x3 + x4 + odd_bit) & 1; int x1 = 2*x1h + x1odd; int y1, y2, y3, y4; int y1h = x1h; y1 = x1; y2 = x2; y3 = x3; y4 = x4; bool boundary = false; if(x1 < 2 || x1 > 1+dim[0] ){ y1 = ((2 + ( (x1 - 2 + dim[0]) % dim[0]))); y1h = y1 >> 1; boundary = true; } if(x2 < 2 || x2 > 1+dim[1] ){ y2 = 2 + ( (x2 - 2 + dim[1]) % dim[1]); boundary = true; } if(x3 < 2 || x3 > 1+dim[2] ){ y3 = 2 + ( (x3 - 2 + dim[2]) % dim[2]); boundary = true; } if(x4 < 2 || x4 > 1+dim[3] ){ y4 = 2 + ( (x4 - 2 + dim[3]) % dim[3]); boundary = true; } if(boundary){ int interior_index = ( y4*extended_dim[2]*extended_dim[1]*extended_dim[0]/2 + y3*extended_dim[1]*extended_dim[0]/2 + y2*extended_dim[0]/2 + y1h + odd_bit*half_extended_volume ); for(int dir=0; dir<4; ++dir){ char* field_ptr = (char*)qdp_field[dir]; memcpy(field_ptr + i*matrix_size, field_ptr + interior_index*matrix_size, matrix_size); } } // if(boundary) } // loop over the extended volume
void* Allocator__realloc(struct Allocator* allocator, const void* original, unsigned long size, const char* fileName, int lineNum) { if (original == NULL) { return Allocator__malloc(allocator, size, fileName, lineNum); } struct Allocator_pvt* context = Identity_check((struct Allocator_pvt*) allocator); check(context); struct Allocator_Allocation_pvt** locPtr = &context->allocations; struct Allocator_Allocation_pvt* origLoc = ((struct Allocator_Allocation_pvt*) original) - 1; for (;;) { struct Allocator_Allocation_pvt* loc = *locPtr; if (loc == NULL) { failure(context, "Reallocation of memory which was not allocated using this allocator.", fileName, lineNum); } checkCanaries(loc, context); if (loc == origLoc) { break; } locPtr = &loc->next; } struct Allocator_Allocation_pvt* nextLoc = origLoc->next; if (size == 0) { // realloc(0) means free() *locPtr = nextLoc; Assert_true(origLoc->pub.size <= context->allocatedHere); context->rootAlloc->spaceAvailable += origLoc->pub.size; context->allocatedHere -= origLoc->pub.size; releaseAllocation(context, origLoc, context->rootAlloc->provider, context->rootAlloc->providerContext); check(context); return NULL; } size_t realSize = getRealSize(size); if (context->rootAlloc->spaceAvailable + origLoc->pub.size < realSize) { failure(context, "Out of memory, limit exceeded.", fileName, lineNum); } context->rootAlloc->spaceAvailable += origLoc->pub.size; context->rootAlloc->spaceAvailable -= realSize; context->allocatedHere -= origLoc->pub.size; context->allocatedHere += realSize; struct Allocator_Allocation_pvt* alloc = context->rootAlloc->provider(context->rootAlloc->providerContext, &origLoc->pub, realSize, allocator); if (alloc == NULL) { failure(context, "Out of memory, realloc() returned NULL.", fileName, lineNum); } alloc->next = nextLoc; alloc->pub.size = realSize; *locPtr = alloc; setCanaries(alloc, context); check(context); return (void*) (alloc + 1); }