Skip to content
Permalink
Browse files

Incomplete

Signed-off-by: unknown <saq10002@iteb-219.ad.engr.uconn.edu>
  • Loading branch information...
unknown
unknown committed Oct 2, 2014
1 parent 5002e16 commit 7bf200bc057207ec312b60d4bd3871ddfb4d03c6
Showing with 204 additions and 173 deletions.
  1. +14 −4 dynarrc/common.h
  2. +0 −120 dynarrc/dynarr.c
  3. +179 −38 dynarrc/dynarr.h
  4. +0 −1 dynarrc/dynarrc.vcxproj
  5. +0 −3 dynarrc/dynarrc.vcxproj.filters
  6. +11 −7 dynarrc/main.c
@@ -54,13 +54,23 @@
#define SIZE_ARR(a) ( ((a)!=NULL) ? sizeof(a) / sizeof((a)[0]) : 0)


// max nodes
#define MAXSEG MaxSeg
#define LOG_MAXSEG LogMaxSeg
#define MAXSEG_REMAINDER_BITMASK MaxSegRemainderBitMask


// types
#define real_t float

// helper macros

// e.g.: structVar.member or structPtr->member
#define MEMBER(structVar, memberop, member) TOKEN_PASTE(TOKEN_PASTE(structVar, memberop), member)


// swap two integers, or pointers, without using temporary storage
__inline void int_swap(unsigned int *var1, unsigned int *var2) {
(*var1) = (*var1) ^ (*var2);
(*var2) = (*var1) ^ (*var2);
(*var1) = (*var1) ^ (*var2);
}


#endif // __dynarr_common_h__
@@ -17,123 +17,3 @@ EXTERN unsigned int MaxSegRemainderBitMask;
SEGALLOC_USE();


// when maximum number of segment banks is reached,
// double MaxSegBanks and
// reallocate the bookkeeping machinery
// returns 0 if bad, 1 if ok
int seg_bank_increase_max(){
void* pVoid;
int bSuccess = 1;
int prevMaxSegBanks = MAX_SEG_BANKS;
// new limit on number of segment banks
MAX_SEG_BANKS <<= 1;

// realloc
if (pVoid = realloc(pSegBanksArr, MaxSegBanks * sizeof(real_t*))){
pSegBanksArr = (real_t**)pVoid;
memset(pSegBanksArr + prevMaxSegBanks, 0, (MaxSegBanks - prevMaxSegBanks) * sizeof(real_t*));
}
else {
printf("\nFatal error: Failed to increase the Maximum number of segment banks."
"\n\tFile: %s\n\tLine: %d\n",
__FILE__, __LINE__);
return 0;
}

if (pVoid = realloc(pSegBankSizeArr, MaxSegBanks * sizeof(int))){
pSegBankSizeArr = (int*)pVoid;
memset(pSegBankSizeArr + prevMaxSegBanks, 0, (MaxSegBanks - prevMaxSegBanks) * sizeof(int));
}
else {
printf("\nFatal error: Failed to increase the Maximum number of segment banks."
"\n\tFile: %s\n\tLine: %d\n",
__FILE__, __LINE__);
return 0;
}

if (pVoid = realloc(pSegBankIndexLimitArr, MaxSegBanks * sizeof(int))){
pSegBankIndexLimitArr = (int*)pVoid;
memset(pSegBankIndexLimitArr + prevMaxSegBanks, 0, (MaxSegBanks - prevMaxSegBanks) * sizeof(int));
}
else {
printf("\nFatal error: Failed to increase the Maximum number of segment banks."
"\n\tFile: %s\n\tLine: %d\n",
__FILE__, __LINE__);
return 0;
}

// ok
return 1;
}

//
// allocate next segment bank and place iInsertPos in appropriate value
//
int seg_bank_alloc_next(){
int numElems = MaxSeg,
round = 0,
iHypotheticalTotalSegsUptoLastActiveBank = 0;
real_t* ptr;
int bCpuGpuAllocDone = 0;

//assert(NumSegBanks < MAX_SEG_BANKS);
if (NumSegBanks >= MAX_SEG_BANKS) {
// increase limit on the number of segment banks
if (!seg_bank_increase_max()){
// no futher alloc possible
SegBankAllocViolation = 1;

printf("\nFatal error: Maximum number of segment banks is reached."
"\n\tFile: %s\n\tLine: %d\n",
__FILE__, __LINE__);
return 0;
}
else{
// great, it is possible to have more segment banks
// continue
}
}

// ok, lets try to allocate one more segment bank
do{
// cpu alloc
do{
numElems >>= (round++);
assert(numElems % 4 == 0); // must be a multiple of 4

ptr = (real_t*)malloc(numElems * NUM_SEG_MEMBERS_IN_ARR * sizeof(real_t));
} while (numElems > 1 && ptr == NULL);
assert(ptr != NULL);
if (ptr == NULL){
// no futher alloc possible
SegBankAllocViolation = 1;

printf("\nFatal error: Failed to allocate next segment bank"
"\n\tFile: %s\n\tLine: %d\n", __FILE__, __LINE__);
return 0;
}

// ok in cpu
pSegBanksArr[NumSegBanks] = ptr;

// update the size of the bank
// it is used when allocating bank in gpu
pSegBankSizeArr[NumSegBanks] = numElems;

// now allocate corresponding bank in gpu
bCpuGpuAllocDone = 1;
} while (bCpuGpuAllocDone == 0);

// great
// initialize everything to zero, this makes all segments initially null
memset(ptr, 0, numElems * NUM_SEG_MEMBERS_IN_ARR * sizeof(real_t));
iHypotheticalTotalSegsUptoLastActiveBank = NumSegBanks * MaxSeg;
// pretend that each segment bank is of size MaxSeg
pSegBankIndexLimitArr[NumSegBanks] = (iHypotheticalTotalSegsUptoLastActiveBank - 1) + numElems;

// finally
iInsertPos = iHypotheticalTotalSegsUptoLastActiveBank;
NumSegBanks++;

return 1;
}
Oops, something went wrong.

0 comments on commit 7bf200b

Please sign in to comment.
You can’t perform that action at this time.