Example #1
0
char* ossimHdf4SubDataset::getTileBuf(const  ossimIrect& rect, ossim_uint32 band)
{
   // bool status = false;
   int32 start[H4_MAX_NC_DIMS], edges[H4_MAX_NC_DIMS];
   if (m_rank == 3)
   {
      start[0] = band;
      start[1] = rect.ul().y;
      start[2] = rect.ul().x;
      edges[0] = 1;
      edges[1] = rect.height(); 
      edges[2] = rect.width(); 
   }
   else if (m_rank == 2)
   {
      start[0] = rect.ul().y;
      start[1] = rect.ul().x;
      edges[0] = rect.height(); 
      edges[1] = rect.width(); 
   }
   
   int32 numValues = rect.width() * rect.height();
   ossim_int32 size = getDataTypeSize(m_dataType);
   
   char* data = new char[size * numValues];
   // intn statusSd = SDreaddata(m_sds_id, start, NULL, edges, (VOIDP)data);
   SDreaddata(m_sds_id, start, NULL, edges, (VOIDP)data);   
  
   return data;
}
Example #2
0
void ossimHdf4SubDataset::initMeta()
{
   m_meta.clear();

   //insert name first
   m_meta.push_back("name: " + ossimString(m_hdfDataType + ":" + m_sd_name));

   char	attrName[100];
   int32 numValues;
   int32 dataType;

   for (ossim_int32 i = 0; i < m_attributes; i++ )
   {
      // Get information about the attribute. Note that the first
      // parameter is an SD interface identifier.
      SDattrinfo(m_sds_id, i, attrName, &dataType, &numValues);
      
      ossim_int32 size = getDataTypeSize(dataType);
      char* attrValue = new char[size * numValues + 1];
      
      SDreadattr(m_sds_id, i, attrValue);

      if ( dataType == DFNT_CHAR8 || dataType == DFNT_UCHAR8 )
      {
         attrValue[numValues] = '\0';
         m_meta.push_back(ossimString(attrName) + ": " + ossimString(attrValue).trim());
      }
      else
      {
         ossimString values = getAttribuitValues(dataType, numValues, attrValue);
         m_meta.push_back(ossimString(attrName) + ": " + values);
      }
      delete [] attrValue;
   }
}
Example #3
0
void VISIBILITY_HIDDEN
calcParam(SubDimInfo* sd)
{
    SubproblemDim* dim = sd->sdim;

    int dataTypeSize = getDataTypeSize(sd->dtype);

    memset(dim, 0, sizeof(sd->sdim));

    dim[0].x      = get(&sd->var[V_L0_X]);
    dim[0].itemX  = get(&sd->var[V_L0_X]);
    dim[0].y      = get(&sd->var[V_L0_Y]);
    dim[0].itemY  = get(&sd->var[V_L0_Y]);
    dim[0].bwidth = get(&sd->var[V_L0_BW]);

    dim[1].x      = get(&sd->var[V_L1_X]);
    dim[1].itemX  = get(&sd->var[V_L1_X]);
    dim[1].y      = get(&sd->var[V_L1_Y]);
    dim[1].itemY  = get(&sd->var[V_L1_Y]);
    dim[1].bwidth = get(&sd->var[V_L1_BW])
            / (dataTypeSize / getDataTypeSize(TYPE_FLOAT));

    if (funcHasTriangMatrix((BlasFunctionID)sd->func) && !sd->is2D) {
        dim[0].itemY  = SUBDIM_UNUSED;
    }

    if (sd->blasLevel == 2) {
        size_t xBlocks;

        xBlocks = dim[0].x / dim[1].x;
        dim[0].x = 1;
        dim[1].itemX = 1;
        dim[1].x = 1;
        if( NULL == sd->pattern->sops->checkCalcDecomp ){
            dim[0].bwidth = dim[1].bwidth * xBlocks;
        }
    }

    calcPGranularity(sd);
}
Example #4
0
/*
*  Checks current dimensionality on a validity
*/
bool VISIBILITY_HIDDEN
isSubDimValid(SubDimInfo* sd)
{
    int j;
    size_t wgX = sd->pgran.wgSize[0];
    size_t wgY = sd->pgran.wgSize[1];
    SubproblemDim l0 = sd->sdim[0];
    SubproblemDim l1 = sd->sdim[1];
    size_t dataTypeSize = getDataTypeSize(sd->dtype);
    size_t dataFloatSize = getDataTypeSize(TYPE_FLOAT);
    int maxRegistr = 64;
    bool ret = true;
    bool inv;
    IgnoreItem* ii = sd->first;

    // if pattern-based validation is available
    if( NULL != sd->pattern->sops->checkCalcDecomp ){

        return sd->pattern->sops->checkCalcDecomp(
            &sd->pgran,
            sd->sdim,
            2,
            sd->dtype,
            PGRAN_CHECK );
    }

    ret = ret && (l1.y >= 4*dataFloatSize/dataTypeSize);

    if (sd->blasLevel == 3) {
        if (!isMatrixAccessColMaj(sd->func, sd->flag, MATRIX_A) ||
                !isMatrixAccessColMaj(sd->func, sd->flag, MATRIX_B)) {
            /* Avoid small bwidth and big x0, y0 for cases other than
             * column major access to both matrixes */
            ret = ret && (l1.bwidth >= 4*dataFloatSize/dataTypeSize);
            ret = ret && (l0.y < 128);
            ret = ret && (l0.x < 128);
        }
    }

    if ( 0 == l1.bwidth ){
        return false;
    }
    else{
        ret = ret && ((l0.bwidth % l1.bwidth) == 0);
        ret = ret && (wgX*wgY == 64);
    }
    //ret = ret && (wgX*wgY < sd->workGroupSizes);
    //ret = ret && (wgX*wgY > 16);
    if (sd->blasLevel == 2) {
        ret = ret && (l0.y > l1.y);
    }
    else {
        ret = ret && (l0.x > l1.x);
        ret = ret && (l0.y > l1.y);
        ret = ret && (l1.x >= 4*dataFloatSize/dataTypeSize);
    }
    if (sd->is2D) {
        bool r = ret;
        ret = ret && (wgY * l1.itemX == l0.x);
        ret = ret && (wgX * l1.itemY == l0.y);
        if (r != ret) {
            return ret;
        }
    }

    if (ret && sd->isSquareBlock) {
        ret = ret &&  (l0.x == l0.y && l0.x == l0.bwidth);
    }

    //if (!(isLdsUsed(sd->pattern) || (sd->isSquareBlock && sd->nrLevel == 2))) {
    //    ret = ret &&  l0.bwidth == l1.bwidth;
    //}

    if (ret) {
        int r ;
        r = (int)(l1.x*l1.bwidth + l1.y*l1.bwidth + l1.x*l1.y);

        r = r * (int)dataTypeSize / sizeof(cl_float4);

        if (r > maxRegistr) {
            return false;
        }
    }

    if  (ret &&  sd->pattern->sops->isFitToLDS != NULL) {
        bool isFitToLDS;
        CLBlasKargs args;

        convKExtraFlagToArg(sd->flag, &args);

        isFitToLDS = sd->pattern->sops->isFitToLDS(sd->sdim, sd->dtype,
                                               sd->ldsSize, &args);
        if (!isFitToLDS)
            return false;
    }

    // Skip ignored dimension
    for (;ii != NULL; ii = ii->next) {
        inv = true;
        for(j = 0; j < V_COUNT; ++j) {
            int v1 = ii->var[j];
            int v2 = get(&sd->var[j]);
            if (v1 == -1) {
                continue;
            }
            if (v1 == v2) {
                continue;
            }
            inv = false;
            break;
        }
        if (inv) {
            ret = false;
        }
    }

    return ret;
}
int
rsNcGetVarsByTypeForColl (rsComm_t *rsComm, ncGetVarInp_t *ncGetVarInp,
ncGetVarOut_t **ncGetVarOut)
{
    int i, j, status;
    int l1descInx;
    openedAggInfo_t *openedAggInfo;
    ncInqInp_t ncInqInp;
    ncGetVarInp_t myNcGetVarInp;
    rodsLong_t timeStart0, timeEnd0, curPos; 
    rodsLong_t eleStart, eleEnd; 
    int timeInxInVar0; 
    rodsLong_t start[NC_MAX_DIMS], stride[NC_MAX_DIMS], count[NC_MAX_DIMS];
    char *buf, *bufPos;
    int len, eleLen, curLen;
    ncGetVarOut_t *myNcGetVarOut = NULL;
    char dataType_PI[NAME_LEN];
    int dataTypeSize;

    *ncGetVarOut = NULL;
    *dataType_PI = '\0';
    l1descInx = ncGetVarInp->ncid;
    openedAggInfo = &L1desc[l1descInx].openedAggInfo;
    if (openedAggInfo->objNcid0 == -1) {
        return NETCDF_AGG_ELE_FILE_NOT_OPENED;
    }
    if (openedAggInfo->ncInqOut0 == NULL) {
        bzero (&ncInqInp, sizeof (ncInqInp));
        ncInqInp.ncid = openedAggInfo->objNcid0;
        ncInqInp.paramType = NC_ALL_TYPE;
        ncInqInp.flags = NC_ALL_FLAG;
        status = rsNcInqDataObj (rsComm, &ncInqInp, &openedAggInfo->ncInqOut0);
        if (status < 0) {
            rodsLogError (LOG_ERROR, status,
              "rsNcGetVarsByTypeForColl: rsNcInqDataObj for %s error",
              openedAggInfo->ncAggInfo->ncObjectName);
            return status;
        }
    }
    timeInxInVar0 = getTimeInxInVar (openedAggInfo->ncInqOut0, 
      ncGetVarInp->varid);

    if (timeInxInVar0 < 0) {
        /* no time dim */
        timeStart0 = curPos = timeEnd0 = 0;
    } else if (timeInxInVar0 >= ncGetVarInp->ndim) {
        rodsLog (LOG_ERROR, 
          "rsNcGetVarsByTypeForColl: timeInxInVar0 %d >= ndim %d",
          timeInxInVar0, ncGetVarInp->ndim);
        return NETCDF_DIM_MISMATCH_ERR;
    } else {
        timeStart0 = curPos = ncGetVarInp->start[timeInxInVar0];
        timeEnd0 = timeStart0 + ncGetVarInp->count[timeInxInVar0] - 1;
    }
    eleStart = 0;
    myNcGetVarInp = *ncGetVarInp;
    bzero (start, sizeof (char) * NC_MAX_DIMS);
    bzero (count, sizeof (char) * NC_MAX_DIMS);
    bzero (stride, sizeof (char) * NC_MAX_DIMS);
    myNcGetVarInp.start = start;
    myNcGetVarInp.count = count;
    myNcGetVarInp.stride = stride;
    for (i = 0; i < ncGetVarInp->ndim; i++) {
         myNcGetVarInp.start[i] = ncGetVarInp->start[i];
         myNcGetVarInp.stride[i] = ncGetVarInp->stride[i];
         myNcGetVarInp.count[i] = ncGetVarInp->count[i];
    }
    len = getSizeForGetVars (ncGetVarInp);
    if (len <= 0) return len;
    dataTypeSize = getDataTypeSize (ncGetVarInp->dataType);
    if (dataTypeSize < 0) return dataTypeSize;
    buf = bufPos = (char *) calloc (len, dataTypeSize);
    curLen = 0;
    for (i = 0; i < openedAggInfo->ncAggInfo->numFiles; i++) {
        eleEnd = eleStart + 
          openedAggInfo->ncAggInfo->ncAggElement[i].arraylen - 1;
        if (curPos >= eleStart && curPos <= eleEnd) {
            /* in range */
            if (i != 0 && i != openedAggInfo->aggElemetInx) {
                status = openAggrFile (rsComm, l1descInx, i);
                if (status < 0) {
                    free (buf);
                    return status;
                }
                bzero (&ncInqInp, sizeof (ncInqInp));
                ncInqInp.ncid = openedAggInfo->objNcid;
                ncInqInp.paramType = NC_ALL_TYPE;
                ncInqInp.flags = NC_ALL_FLAG;
                status = rsNcInqDataObj (rsComm, &ncInqInp, 
                  &openedAggInfo->ncInqOut);
                if (status < 0) {
                    rodsLogError (LOG_ERROR, status,
                      "rsNcGetVarsByTypeForColl: rsNcInqDataObj error for %s",
                      openedAggInfo->ncAggInfo->ncObjectName);
                    free (buf);
                    return status;
                }
            }
            if (i != 0) {
                char *varName0 = NULL;
                myNcGetVarInp.ncid =  openedAggInfo->objNcid;
                /* varid can be different than ele 0 */
                for (j = 0; j < openedAggInfo->ncInqOut0->nvars; j++) {
                    if (openedAggInfo->ncInqOut0->var[j].id == 
                      ncGetVarInp->varid) {
                        varName0 = openedAggInfo->ncInqOut0->var[j].name;
                        break;
                    }
                } 
                if (varName0 == NULL) {
                    free (buf);
                    return NETCDF_DEF_VAR_ERR;
                }
                myNcGetVarInp.varid = -1;
                for (j = 0; j < openedAggInfo->ncInqOut0->nvars; j++) {
                    if (strcmp (varName0, 
                      openedAggInfo->ncInqOut0->var[j].name) == 0) {
                        myNcGetVarInp.varid = 
                          openedAggInfo->ncInqOut0->var[j].id;
                        break;
                    }
                }
                if (myNcGetVarInp.varid == -1) {
                    free (buf);
                    return NETCDF_DEF_VAR_ERR;
                }
            } else {
                myNcGetVarInp.ncid =  openedAggInfo->objNcid0;
            }
            /* adjust the start, count */ 
            if (timeInxInVar0 >= 0) {
                myNcGetVarInp.start[timeInxInVar0] = curPos - eleStart;
                if (timeEnd0 >= eleEnd) {
                    myNcGetVarInp.count[timeInxInVar0] = eleEnd - curPos + 1;
                } else {
                    myNcGetVarInp.count[timeInxInVar0] = timeEnd0 - curPos + 1;
                }
                /* adjust curPos. need to take stride into account */
                curPos += myNcGetVarInp.count[timeInxInVar0];
                if (myNcGetVarInp.stride[timeInxInVar0] > 0) { 
                    int mystride = myNcGetVarInp.stride[timeInxInVar0];
                    int remaine = curPos % mystride;
                    if (remaine > 0) {
                        curPos = (curPos / mystride) * (mystride + 1);
                    }
                }
            }
            eleLen = getSizeForGetVars (&myNcGetVarInp);
            status = rsNcGetVarsByTypeForObj (rsComm, &myNcGetVarInp,
             &myNcGetVarOut);
            if (status < 0) {
                rodsLogError (LOG_ERROR, status,
                "rsNcGetVarsByTypeForColl: rsNcGetVarsByTypeForObj %s err",
                  openedAggInfo->ncAggInfo->ncObjectName);
                free (buf);
                return status;
            }
            if (myNcGetVarOut->dataArray->len > 0) {
                curLen += myNcGetVarOut->dataArray->len;
                if (curLen > len) {
                    rodsLog (LOG_ERROR,
                      "rsNcGetVarsByTypeForColl: curLen %d > total len %d",
                      curLen, len);
                    free (buf);
                    return NETCDF_VARS_DATA_TOO_BIG;
                }
                memcpy (bufPos, myNcGetVarOut->dataArray->buf,
                 myNcGetVarOut->dataArray->len * dataTypeSize);
                bufPos += myNcGetVarOut->dataArray->len * dataTypeSize;
                rstrcpy (dataType_PI, myNcGetVarOut->dataType_PI, NAME_LEN);
                freeNcGetVarOut (&myNcGetVarOut);
            }
        }
        if (curPos > timeEnd0) break;
        eleStart = eleEnd + 1;
    }
    if (status >= 0) {
        if (strlen (dataType_PI) == 0) return status;
        *ncGetVarOut = (ncGetVarOut_t *) calloc (1, sizeof (ncGetVarOut_t));
        (*ncGetVarOut)->dataArray = (dataArray_t *) 
          calloc (1, sizeof (dataArray_t));
        rstrcpy ((*ncGetVarOut)->dataType_PI, dataType_PI, NAME_LEN);
        (*ncGetVarOut)->dataArray->len = len;
        (*ncGetVarOut)->dataArray->type = ncGetVarInp->dataType;
        (*ncGetVarOut)->dataArray->buf = buf;
    } else {
        free (buf);
    }
    return status;
}