int CVxParamDistribution::InitializeIO(vx_context context, vx_graph graph, vx_reference ref, const char * io_params) { // save reference object and get object attributes m_vxObjRef = ref; m_distribution = (vx_distribution)m_vxObjRef; ERROR_CHECK(vxQueryDistribution(m_distribution, VX_DISTRIBUTION_ATTRIBUTE_BINS, &m_numBins, sizeof(m_numBins))); ERROR_CHECK(vxQueryDistribution(m_distribution, VX_DISTRIBUTION_ATTRIBUTE_OFFSET, &m_offset, sizeof(m_offset))); ERROR_CHECK(vxQueryDistribution(m_distribution, VX_DISTRIBUTION_ATTRIBUTE_RANGE, &m_range, sizeof(m_range))); // process I/O parameters if (*io_params == ':') io_params++; while (*io_params) { char ioType[64], fileName[256]; io_params = ScanParameters(io_params, "<io-operation>,<parameter>", "s,S", ioType, fileName); if (!_stricmp(ioType, "read")) { // read request syntax: read,<fileName>[,ascii|binary] m_fileNameRead.assign(RootDirUpdated(fileName)); m_fileNameForReadHasIndex = (m_fileNameRead.find("%") != m_fileNameRead.npos) ? true : false; m_readFileIsBinary = (m_fileNameRead.find(".txt") != m_fileNameRead.npos) ? false : true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",ascii|binary", ",s", option); if (!_stricmp(option, "ascii")) { m_readFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_readFileIsBinary = true; } else ReportError("ERROR: invalid distribution read option: %s\n", option); } } else if (!_stricmp(ioType, "write")) { // write request syntax: write,<fileName>[,ascii|binary] m_fileNameWrite.assign(RootDirUpdated(fileName)); m_writeFileIsBinary = (m_fileNameWrite.find(".txt") != m_fileNameWrite.npos) ? false : true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",ascii|binary", ",s", option); if (!_stricmp(option, "ascii")) { m_writeFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_writeFileIsBinary = true; } else ReportError("ERROR: invalid distribution write option: %s\n", option); } } else if (!_stricmp(ioType, "compare")) { // compare syntax: compare,fileName[,ascii|binary] m_fileNameCompare.assign(RootDirUpdated(fileName)); m_compareFileIsBinary = (m_fileNameCompare.find(".txt") != m_fileNameCompare.npos) ? false : true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",ascii|binary", ",s", option); if (!_stricmp(option, "ascii")) { m_compareFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_compareFileIsBinary = true; } else ReportError("ERROR: invalid distribution compare option: %s\n", option); } } else if (!_stricmp(ioType, "view")) { m_displayName.assign(fileName); m_paramList.push_back(this); } else ReportError("ERROR: invalid distribution operation: %s\n", ioType); if (*io_params == ':') io_params++; else if (*io_params) ReportError("ERROR: unexpected character sequence in parameter specification: %s\n", io_params); } return 0; }
int CVxParamArray::InitializeIO(vx_context context, vx_graph graph, vx_reference ref, const char * io_params) { // save reference object and get object attributes m_vxObjRef = ref; m_array = (vx_array)m_vxObjRef; ERROR_CHECK(vxQueryArray(m_array, VX_ARRAY_ATTRIBUTE_ITEMTYPE, &m_format, sizeof(m_format))); ERROR_CHECK(vxQueryArray(m_array, VX_ARRAY_ATTRIBUTE_CAPACITY, &m_capacity, sizeof(m_capacity))); ERROR_CHECK(vxQueryArray(m_array, VX_ARRAY_ATTRIBUTE_ITEMSIZE, &m_itemSize, sizeof(m_itemSize))); // process I/O parameters if (*io_params == ':') io_params++; while (*io_params) { char ioType[64], fileName[256]; io_params = ScanParameters(io_params, "<io-operation>,<parameter>", "s,S", ioType, fileName); if (!_stricmp(ioType, "read")) { // read request syntax: read,<fileName>[,ascii|binary] m_fileNameRead.assign(RootDirUpdated(fileName)); m_fileNameForReadHasIndex = (m_fileNameRead.find("%") != m_fileNameRead.npos) ? true : false; m_readFileIsBinary = (m_fileNameRead.find(".txt") != m_fileNameRead.npos) ? false : true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",ascii|binary", ",s", option); if (!_stricmp(option, "ascii")) { m_readFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_readFileIsBinary = true; } else ReportError("ERROR: invalid array read option: %s\n", option); } } else if (!_stricmp(ioType, "write")) { // write request syntax: write,<fileName>[,ascii|binary] m_fileNameWrite.assign(RootDirUpdated(fileName)); m_writeFileIsBinary = (m_fileNameWrite.find(".txt") != m_fileNameWrite.npos) ? false : true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",ascii|binary", ",s", option); if (!_stricmp(option, "ascii")) { m_writeFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_writeFileIsBinary = true; } else ReportError("ERROR: invalid array write option: %s\n", option); } } else if (!_stricmp(ioType, "compare")) { // compare syntax: compare,fileName[,ascii|binary][,err{<x>;<y>[;<strength>][;<%mismatch>]}][,log{<fileName>}] m_fileNameCompareLog = ""; m_fileNameCompare.assign(RootDirUpdated(fileName)); m_compareFileIsBinary = (m_fileNameCompare.find(".txt") != m_fileNameCompare.npos) ? false : true; while (*io_params == ',') { char option[256]; io_params = ScanParameters(io_params, ",ascii|binary|err{<x>;<y>[;<strength>][;<%mismatch>]}|log{<fileName>}", ",S", option); if (!_stricmp(option, "ascii")) { m_compareFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_compareFileIsBinary = true; } else if (!_strnicmp(option, "err{", 4)) { if (m_format == VX_TYPE_KEYPOINT) { const char * p = ScanParameters(&option[3], "{<x>;<y>;<strength>[;<%mismatch>]}", "{d;d;f", &m_errX, &m_errY, &m_errStrength); if (*p == ';') { ScanParameters(p, ";<%mismatch>}", ";f}", &m_errMismatchPercent); } } else if (m_format == VX_TYPE_COORDINATES2D) { const char * p = ScanParameters(&option[3], "{<x>;<y>[;<%mismatch>]}", "{d;d", &m_errX, &m_errY); if (*p == ';') { ScanParameters(p, ";<%mismatch>}", ";f}", &m_errMismatchPercent); } } else ReportError("ERROR: array compare option not supported for this array: %s\n", option); } else if (!_strnicmp(option, "log{", 4)) { option[strlen(option) - 1] = 0; m_fileNameCompareLog.assign(RootDirUpdated(&option[4])); } else ReportError("ERROR: invalid array compare option: %s\n", option); } } else if (!_stricmp(ioType, "view")) { m_displayName.assign(fileName); m_paramList.push_back(this); } else if (!_stricmp(ioType, "directive") && (!_stricmp(fileName, "VX_DIRECTIVE_AMD_COPY_TO_OPENCL") || !_stricmp(fileName, "sync-cl-write"))) { m_useSyncOpenCLWriteDirective = true; } else if (!_stricmp(ioType, "init")) { m_fileNameRead.assign(RootDirUpdated(fileName)); m_fileNameForReadHasIndex = (m_fileNameRead.find("%") != m_fileNameRead.npos) ? true : false; m_readFileIsBinary = (m_fileNameRead.find(".txt") != m_fileNameRead.npos) ? false : true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",ascii|binary", ",s", option); if (!_stricmp(option, "ascii")) { m_readFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_readFileIsBinary = true; } else ReportError("ERROR: invalid array init option: %s\n", option); } if (ReadFrame(0) < 0) ReportError("ERROR: reading from input file for array init\n"); } else ReportError("ERROR: invalid array operation: %s\n", ioType); if (*io_params == ':') io_params++; else if (*io_params) ReportError("ERROR: unexpected character sequence in parameter specification: %s\n", io_params); } return 0; }
int CVxParamRemap::InitializeIO(vx_context context, vx_graph graph, vx_reference ref, const char * io_params) { // save reference object and get object attributes m_vxObjRef = ref; m_remap = (vx_remap)m_vxObjRef; ERROR_CHECK(vxQueryRemap(m_remap, VX_REMAP_ATTRIBUTE_SOURCE_WIDTH, &m_srcWidth, sizeof(m_srcWidth))); ERROR_CHECK(vxQueryRemap(m_remap, VX_REMAP_ATTRIBUTE_SOURCE_HEIGHT, &m_srcHeight, sizeof(m_srcHeight))); ERROR_CHECK(vxQueryRemap(m_remap, VX_REMAP_ATTRIBUTE_DESTINATION_WIDTH, &m_dstWidth, sizeof(m_dstWidth))); ERROR_CHECK(vxQueryRemap(m_remap, VX_REMAP_ATTRIBUTE_DESTINATION_HEIGHT, &m_dstHeight, sizeof(m_dstHeight))); // process I/O parameters if (*io_params == ':') io_params++; while (*io_params) { char ioType[64], fileName[256]; io_params = ScanParameters(io_params, "<io-operation>,<parameter>", "s,S", ioType, fileName); if (!_stricmp(ioType, "read")) { m_fileNameRead.assign(RootDirUpdated(fileName)); m_usingMultiFrameCapture = (m_fileNameRead.find("%") != std::string::npos) ? true : false; m_readFileIsBinary = (m_fileNameRead.find(".txt") != m_fileNameRead.npos) ? false : true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",ascii|binary", ",s", option); if (!_stricmp(option, "ascii")) { m_readFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_readFileIsBinary = true; } else ReportError("ERROR: invalid remap read option: %s\n", option); } } else if (!_stricmp(ioType, "write")) { m_fileNameWrite.assign(RootDirUpdated(fileName)); } else if (!_stricmp(ioType, "compare")) { // compare request syntax: compare,<fileName>[,err{<x>;<y>}] m_fileNameCompare.assign(RootDirUpdated(fileName)); while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",err{<x>;<y>}", ",s", option); if (!_strnicmp(option, "err{", 4)) { ScanParameters(&option[3], "{<errX>;<errY>}", "{f;f}", &m_xyErr[0], &m_xyErr[1]); } else ReportError("ERROR: invalid remap compare option: %s\n", option); } } else if (!_stricmp(ioType, "directive") && (!_stricmp(fileName, "VX_DIRECTIVE_AMD_COPY_TO_OPENCL") || !_stricmp(fileName, "sync-cl-write"))) { m_useSyncOpenCLWriteDirective = true; } else if (!_stricmp(ioType, "init")) { const char * patternName = fileName; if (!_stricmp(patternName, "same")) { for (vx_uint32 y = 0; y < m_dstHeight; y++){ for (vx_uint32 x = 0; x < m_dstWidth; x++){ vx_float32 sx = (vx_float32)x, sy = (vx_float32)y; vx_status status = vxSetRemapPoint(m_remap, x, y, sx, sy); if (status) { printf("ERROR: vxSetRemapPoint(*,%d,%d,%g,%g) failed, status = %d\n", x, y, sx, sy, status); return -1; } } } } else if (!_stricmp(patternName, "rotate-90")) { for (vx_uint32 y = 0; y < m_dstHeight; y++){ for (vx_uint32 x = 0; x < m_dstWidth; x++){ vx_float32 sx = (vx_float32)m_dstHeight - 1 - y, sy = (vx_float32)x; vx_status status = vxSetRemapPoint(m_remap, x, y, sx, sy); if (status) { printf("ERROR: vxSetRemapPoint(*,%d,%d,%g,%g) failed, status = %d\n", x, y, sx, sy, status); return -1; } } } } else if (!_stricmp(patternName, "rotate-180")) { for (vx_uint32 y = 0; y < m_dstHeight; y++){ for (vx_uint32 x = 0; x < m_dstWidth; x++){ vx_float32 sx = (vx_float32)m_dstWidth - 1 - x, sy = (vx_float32)m_dstHeight - 1 - y; vx_status status = vxSetRemapPoint(m_remap, x, y, sx, sy); if (status) { printf("ERROR: vxSetRemapPoint(*,%d,%d,%g,%g) failed, status = %d\n", x, y, sx, sy, status); return -1; } } } } else if (!_stricmp(patternName, "rotate-270")) { for (vx_uint32 y = 0; y < m_dstHeight; y++){ for (vx_uint32 x = 0; x < m_dstWidth; x++){ vx_float32 sx = (vx_float32)y, sy = (vx_float32)m_dstWidth - 1 - x; vx_status status = vxSetRemapPoint(m_remap, x, y, sx, sy); if (status) { printf("ERROR: vxSetRemapPoint(*,%d,%d,%g,%g) failed, status = %d\n", x, y, sx, sy, status); return -1; } } } } else if (!_stricmp(patternName, "scale")) { for (vx_uint32 y = 0; y < m_dstHeight; y++){ for (vx_uint32 x = 0; x < m_dstWidth; x++){ vx_float32 sx = (x + 0.5f) * (vx_float32)m_srcWidth / (vx_float32)m_dstWidth - 0.5f; vx_float32 sy = (y + 0.5f) * (vx_float32)m_srcHeight / (vx_float32)m_dstHeight - 0.5f; vx_status status = vxSetRemapPoint(m_remap, x, y, sx, sy); if (status) { printf("ERROR: vxSetRemapPoint(*,%d,%d,%g,%g) failed, status = %d\n", x, y, sx, sy, status); return -1; } } } } else if (!_stricmp(patternName, "hflip")) { for (vx_uint32 y = 0; y < m_dstHeight; y++){ for (vx_uint32 x = 0; x < m_dstWidth; x++){ vx_float32 sx = (vx_float32)m_dstWidth - 1 - x, sy = (vx_float32)y; vx_status status = vxSetRemapPoint(m_remap, x, y, sx, sy); if (status) { printf("ERROR: vxSetRemapPoint(*,%d,%d,%g,%g) failed, status = %d\n", x, y, sx, sy, status); return -1; } } } } else if (!_stricmp(patternName, "vflip")) { for (vx_uint32 y = 0; y < m_dstHeight; y++){ for (vx_uint32 x = 0; x < m_dstWidth; x++){ vx_float32 sx = (vx_float32)x, sy = (vx_float32)m_dstHeight - 1 - y; vx_status status = vxSetRemapPoint(m_remap, x, y, sx, sy); if (status) { printf("ERROR: vxSetRemapPoint(*,%d,%d,%g,%g) failed, status = %d\n", x, y, sx, sy, status); return -1; } } } } else { // initialize from binary file FILE * fp = fopen(fileName, "rb"); if (!fp) ReportError("ERROR: CVxParamRemap::InitializeIO: unable to open: %s\n", fileName); for (vx_uint32 y = 0; y < m_dstHeight; y++){ for (vx_uint32 x = 0; x < m_dstWidth; x++){ vx_float32 src_xy[2]; if (fread(src_xy, sizeof(src_xy), 1, fp) != 1) ReportError("ERROR: detected EOF at (%d,%d) on remap input file: %s\n", x, y, fileName); ERROR_CHECK(vxSetRemapPoint(m_remap, x, y, src_xy[0], src_xy[1])); } } fclose(fp); } } else { printf("ERROR: invalid remap I/O operation: %s\n", ioType); return -1; } if (*io_params == ':') io_params++; else if (*io_params) ReportError("ERROR: unexpected character sequence in parameter specification: %s\n", io_params); } return 0; }
int CVxParamTensor::InitializeIO(vx_context context, vx_graph graph, vx_reference ref, const char * io_params) { // save reference object and get object attributes m_vxObjRef = ref; m_tensor = (vx_tensor)m_vxObjRef; ERROR_CHECK(vxQueryTensor(m_tensor, VX_TENSOR_NUMBER_OF_DIMS, &m_num_of_dims, sizeof(m_num_of_dims))); ERROR_CHECK(vxQueryTensor(m_tensor, VX_TENSOR_DIMS, &m_dims, sizeof(m_dims[0])*m_num_of_dims)); ERROR_CHECK(vxQueryTensor(m_tensor, VX_TENSOR_DATA_TYPE, &m_data_type, sizeof(m_data_type))); ERROR_CHECK(vxQueryTensor(m_tensor, VX_TENSOR_FIXED_POINT_POSITION, &m_fixed_point_pos, sizeof(vx_uint8))); if(m_data_type == VX_TYPE_UINT8 || m_data_type == VX_TYPE_INT8) m_size = 1; else if(m_data_type == VX_TYPE_UINT16 || m_data_type == VX_TYPE_INT16 || m_data_type == VX_TYPE_FLOAT16) m_size = 2; else m_size = 4; for (vx_uint32 i = 0; i < m_num_of_dims; i++) { m_stride[i] = m_size; m_size *= m_dims[i]; } m_data = new vx_uint8[m_size]; if (!m_data) ReportError("ERROR: memory allocation failed for tensor: %u\n", (vx_uint32)m_size); // process I/O parameters if (*io_params == ':') io_params++; while (*io_params) { char ioType[64], fileName[256]; io_params = ScanParameters(io_params, "<io-operation>,<parameter>", "s,S", ioType, fileName); if (!_stricmp(ioType, "read")) { // read request syntax: read,<fileName>[,ascii|binary] m_fileNameRead.assign(RootDirUpdated(fileName)); m_fileNameForReadHasIndex = (m_fileNameRead.find("%") != m_fileNameRead.npos) ? true : false; m_readFileIsBinary = true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",binary", ",s", option); if (!_stricmp(option, "binary")) { m_readFileIsBinary = true; } else ReportError("ERROR: invalid tensor read option: %s\n", option); } } else if (!_stricmp(ioType, "init")) { // init request syntax: init,<fileName> if(!_strnicmp(fileName, "@fill~f32~", 10)) { float value = (float)atof(&fileName[10]); float * buf = (float *)m_data; for(size_t i = 0; i < m_size/4; i++) buf[i] = value; } else if(!_strnicmp(fileName, "@fill~i32~", 10)) { vx_int32 value = atoi(&fileName[10]); vx_int32 * buf = (vx_int32 *)m_data; for(size_t i = 0; i < m_size/4; i++) buf[i] = value; } else if(!_strnicmp(fileName, "@fill~i16~", 10)) { vx_int16 value = (vx_int16)atoi(&fileName[10]); vx_int16 * buf = (vx_int16 *)m_data; for(size_t i = 0; i < m_size/2; i++) buf[i] = value; } else if(!_strnicmp(fileName, "@fill~u8~", 9)) { int value = atoi(&fileName[9]); memset(m_data, value, m_size); } else { int count = 1; const char * tensorFileName = fileName; if(!_strnicmp(tensorFileName, "@repeat~", 8)) { tensorFileName += 8; for(count = 0; *tensorFileName >= '0' && *tensorFileName <= '9'; tensorFileName++) { count = count * 10 + *tensorFileName - '0'; } if(*tensorFileName++ != '~' || count < 1) ReportError("ERROR: invalid init @repeat~<n>~fileName syntax -- %s\n", fileName); if((m_size % count) != 0) ReportError("ERROR: file size is not multiple of tensor size -- %s\n", fileName); } if(!_stricmp(fileName + strlen(fileName) - 4, ".dat")) { ReportError("ERROR: read from .dat files not supported: %s\n", fileName); } FILE * fp = fopen(RootDirUpdated(tensorFileName), "rb"); if (!fp) { ReportError("ERROR: Unable to open: %s\n", tensorFileName); } vx_size size = m_size / count; if (fread(m_data, 1, size, fp) != size) ReportError("ERROR: not enough data (%d bytes) in %s\n", (vx_uint32)size, tensorFileName); for(int i = 1; i < count; i++) { memcpy(m_data + i * size, m_data, size); } vx_status status = vxCopyTensorPatch(m_tensor, m_num_of_dims, nullptr, nullptr, m_stride, m_data, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST); fclose(fp); if (status != VX_SUCCESS) ReportError("ERROR: vxCopyTensorPatch: write failed (%d)\n", status); } } else if (!_stricmp(ioType, "write")) { // write request syntax: write,<fileName>[,ascii|binary] m_fileNameWrite.assign(RootDirUpdated(fileName)); m_writeFileIsBinary = true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",binary", ",s", option); if (!_stricmp(option, "binary")) { m_writeFileIsBinary = true; } else ReportError("ERROR: invalid tensor write option: %s\n", option); } } else if (!_stricmp(ioType, "compare")) { // write request syntax: compare,<fileName>[,ascii|binary] m_fileNameCompare.assign(RootDirUpdated(fileName)); m_compareFileIsBinary = true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",binary|maxerr=<value>|avgerr=<value>", ",s", option); if (!_stricmp(option, "binary")) { m_compareFileIsBinary = true; } else if (!_strnicmp(option, "maxerr=", 7)) { m_maxErrorLimit = (float)atof(&option[7]); m_avgErrorLimit = 1e20f; } else if (!_strnicmp(option, "avgerr=", 7)) { m_avgErrorLimit = (float)atof(&option[7]); m_maxErrorLimit = 1e20f; } else ReportError("ERROR: invalid tensor compare option: %s\n", option); } } else if (!_stricmp(ioType, "directive") && (!_stricmp(fileName, "VX_DIRECTIVE_AMD_COPY_TO_OPENCL") || !_stricmp(fileName, "sync-cl-write"))) { m_useSyncOpenCLWriteDirective = true; } else ReportError("ERROR: invalid tensor operation: %s\n", ioType); if (*io_params == ':') io_params++; else if (*io_params) ReportError("ERROR: unexpected character sequence in parameter specification: %s\n", io_params); } return 0; }
int main(int argc, char * argv[]) { // process command-line options const char * program = "runvx.exe"; bool verbose = false; bool enableMultiFrameProcessing = false; bool framesEofRequested = true; bool enableDumpGDF = false, enableScheduleGraph = false; bool pauseBeforeExit = false; bool enableDumpProfile = false; bool disableVirtual = false; bool discardCompareErrors = false; vx_uint32 defaultTargetAffinity = 0; vx_uint32 defaultTargetInfo = 0; bool doSetGraphOptimizerFlags = false; vx_uint32 graphOptimizerFlags = 0; int arg, frameStart = 0, frameEnd = 1; bool frameCountSpecified = false; int waitKeyDelayInMilliSeconds = -1; // -ve indicates no user preference for (arg = 1; arg < argc; arg++){ if (argv[arg][0] == '-'){ if (!_stricmp(argv[arg], "-h")) { show_usage(program, true); exit(0); } else if (!_stricmp(argv[arg], "-v")) { verbose ^= true; } else if (!strncmp(argv[arg], "--", 2)) { // skip specified number of arguments: --[#] (default just skip --) arg += atoi(&argv[arg][2]); } else if (!_strnicmp(argv[arg], "-root:", 6)) { SetRootDir(argv[arg] + 6); } else if (!_strnicmp(argv[arg], "-frames:", 8)) { int spos = 8; while (argv[arg][spos]) { if (argv[arg][spos] == ',') spos++; else if (!_strnicmp(argv[arg], "live", 4)) { enableMultiFrameProcessing = true; spos += 4; } else if (!_strnicmp(argv[arg], "eof", 3)) { framesEofRequested = true; spos += 3; } else { int k = sscanf(&argv[arg][spos], "%d:%d", &frameStart, &frameEnd); if (k == 1) { frameEnd = frameStart, frameStart = 0; } else if (k != 2) { printf("ERROR: invalid -frames option\n"); return -1; } frameCountSpecified = true; while (argv[arg][spos] && argv[arg][spos] != ',') spos++; } } } else if (!_strnicmp(argv[arg], "-affinity:", 10)) { if (!_strnicmp(&argv[arg][10], "cpu", 3)) defaultTargetAffinity = AGO_TARGET_AFFINITY_CPU; else if (!_strnicmp(&argv[arg][10], "gpu", 3)) defaultTargetAffinity = AGO_TARGET_AFFINITY_GPU; else { printf("ERROR: unsupported affinity target: %s\n", &argv[arg][10]); return -1; } if (argv[arg][13] >= '0' && argv[arg][13] <= '9') defaultTargetInfo = atoi(&argv[arg][13]); } else if (!_stricmp(argv[arg], "-dump-profile")) { enableDumpProfile = true; } else if (!_stricmp(argv[arg], "-dump-gdf") || !_stricmp(argv[arg], "-ago-dump")) { // TBD: remove -ago-dump enableDumpGDF = true; } else if (!_stricmp(argv[arg], "-discard-compare-errors")) { discardCompareErrors = true; } else if (!_stricmp(argv[arg], "-use-schedule-graph")) { enableScheduleGraph = true; } else if (!_stricmp(argv[arg], "-disable-virtual")) { disableVirtual = true; } else if (!_strnicmp(argv[arg], "-graph-optimizer-flags:", 23)) { if (sscanf(&argv[arg][23], "%i", &graphOptimizerFlags) == 1) { doSetGraphOptimizerFlags = true; } else { printf("ERROR: invalid graph optimizer flags: %s\n", argv[arg]); return -1; } } else if (!_strnicmp(argv[arg], "-key-wait-delay:", 16)) { (void)sscanf(&argv[arg][16], "%i", &waitKeyDelayInMilliSeconds); } else if (!_stricmp(argv[arg], "-pause")) { pauseBeforeExit = true; } else { printf("ERROR: invalid option: %s\n", argv[arg]); return -1; } } else break; } if (arg == argc) { show_usage(program, false); return -1; } int argCount = argc - arg - 2; fflush(stdout); CVxEngine engine; int errorCode = 0; try { // initialize engine if (engine.Initialize(argCount, defaultTargetAffinity, defaultTargetInfo, enableScheduleGraph, disableVirtual) < 0) throw - 1; if (doSetGraphOptimizerFlags) { engine.SetGraphOptimizerFlags(graphOptimizerFlags); } engine.SetConfigOptions(verbose, discardCompareErrors, enableDumpProfile, enableDumpGDF, waitKeyDelayInMilliSeconds); engine.SetFrameCountOptions(enableMultiFrameProcessing, framesEofRequested, frameCountSpecified, frameStart, frameEnd); fflush(stdout); // pass parameters to the engine: note that shell takes no extra parameters whereas node and file take extra parameter int argParamOffset = (!_stricmp(argv[arg], "shell")) ? 1 : 2; for (int i = 0, j = 0; i < argCount; i++) { char * param = argv[arg + argParamOffset + i]; if (engine.SetParameter(j++, param) < 0) throw -1; } fflush(stdout); // get full GDF text char * fullText = nullptr; if (!_stricmp(argv[arg], "file")) { if ((arg+1) == argc) ReportError("ERROR: missing file name on command-line (see help for details)\n"); arg++; const char * fileName = RootDirUpdated(argv[arg]); size_t size = strlen("include") + 1 + strlen(fileName) + 1; fullText = new char[size]; sprintf(fullText, "include %s", fileName); } else if (!_stricmp(argv[arg], "node")) { if ((arg + 1) == argc) ReportError("ERROR: missing kernel name on command-line (see help for details)\n"); int paramCount = argc - arg - 2; arg++; size_t size = strlen("node") + 1 + strlen(argv[arg]) + paramCount*6 + 1; fullText = new char[size]; sprintf(fullText, "node %s", argv[arg]); for (int i = 0, j = 0; i < paramCount; i++) sprintf(fullText + strlen(fullText), " $%d", j++ + 1); } else if (!_stricmp(argv[arg], "shell")) { // nothing to do } else { printf("ERROR: invalid command: %s (see help for details)\n", argv[arg]); throw -1; } if (fullText) { // process the GDF if (engine.BuildAndProcessGraph(0, fullText, false) < 0) throw - 1; delete[] fullText; } else { // run shell if (engine.Shell(0) < 0) throw - 1; } fflush(stdout); if (engine.Shutdown() < 0) throw -1; fflush(stdout); } catch (int errorCode_) { fflush(stdout); engine.DisableWaitForKeyPress(); errorCode = errorCode_; } if (pauseBeforeExit) { fflush(stdout); printf("Press ENTER to exit ...\n"); while (getchar() != '\n') ; } return errorCode; }
int CVxParamMatrix::InitializeIO(vx_context context, vx_graph graph, vx_reference ref, const char * io_params) { // save reference object and get object attributes m_vxObjRef = ref; m_matrix = (vx_matrix)m_vxObjRef; ERROR_CHECK(vxQueryMatrix(m_matrix, VX_MATRIX_ATTRIBUTE_TYPE, &m_data_type, sizeof(m_data_type))); ERROR_CHECK(vxQueryMatrix(m_matrix, VX_MATRIX_ATTRIBUTE_COLUMNS, &m_columns, sizeof(m_columns))); ERROR_CHECK(vxQueryMatrix(m_matrix, VX_MATRIX_ATTRIBUTE_ROWS, &m_rows, sizeof(m_rows))); ERROR_CHECK(vxQueryMatrix(m_matrix, VX_MATRIX_ATTRIBUTE_SIZE, &m_size, sizeof(m_size))); // process I/O parameters if (*io_params == ':') io_params++; while (*io_params) { char ioType[64], fileName[256]; io_params = ScanParameters(io_params, "<io-operation>,<parameter>", "s,S", ioType, fileName); if (!_stricmp(ioType, "read")) { // read request syntax: read,<fileName>[,ascii|binary] m_fileNameRead.assign(RootDirUpdated(fileName)); m_fileNameForReadHasIndex = (m_fileNameRead.find("%") != m_fileNameRead.npos) ? true : false; m_readFileIsBinary = (m_fileNameRead.find(".txt") != m_fileNameRead.npos) ? false : true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",ascii|binary", ",s", option); if (!_stricmp(option, "ascii")) { m_readFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_readFileIsBinary = true; } else ReportError("ERROR: invalid matrix read option: %s\n", option); } } else if (!_stricmp(ioType, "write")) { // write request syntax: write,<fileName>[,ascii|binary] m_fileNameWrite.assign(RootDirUpdated(fileName)); m_writeFileIsBinary = (m_fileNameWrite.find(".txt") != m_fileNameWrite.npos) ? false : true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",ascii|binary", ",s", option); if (!_stricmp(option, "ascii")) { m_writeFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_writeFileIsBinary = true; } else ReportError("ERROR: invalid matrix write option: %s\n", option); } } else if (!_stricmp(ioType, "compare")) { // compare request syntax: compare,<fileName>[,ascii|binary][,err{<tolerance>}] m_fileNameCompare.assign(RootDirUpdated(fileName)); m_compareFileIsBinary = (m_fileNameCompare.find(".txt") != m_fileNameCompare.npos) ? false : true; while (*io_params == ',') { char option[64]; io_params = ScanParameters(io_params, ",ascii|binary|err{<tolerance>}", ",s", option); if (!_stricmp(option, "ascii")) { m_compareFileIsBinary = false; } else if (!_stricmp(option, "binary")) { m_compareFileIsBinary = true; } else if (!_strnicmp(option, "err{", 4)) { ScanParameters(&option[3], "{<tolerance>}", "{f}", &m_errTolerance); } else ReportError("ERROR: invalid matrix compare option: %s\n", option); } } else if (!_stricmp(ioType, "init")) { // write request syntax: init,{<value1>;<value2>;...<valueN>} NULLPTR_CHECK(m_bufForAccess = new vx_uint8[m_size]); vx_size index = 0; char fmt[3] = { '{', (m_data_type == VX_TYPE_FLOAT32) ? 'f' : 'd', 0 }; for (const char * s = fileName; *s && index < (m_columns * m_rows); fmt[0] = ';', index++) { if (m_data_type == VX_TYPE_INT32 || m_data_type == VX_TYPE_UINT8) { vx_uint32 value; s = ScanParameters(s, "<value>", fmt, &value); if (m_data_type == VX_TYPE_UINT8) ((vx_uint8 *)m_bufForAccess)[index] = (vx_uint8)value; else ((vx_int32 *)m_bufForAccess)[index] = value; } else if (m_data_type == VX_TYPE_FLOAT32) { s = ScanParameters(s, "<value>", fmt, &((vx_float32 *)m_bufForAccess)[index]); } else ReportError("ERROR: matrix init option not support for data_type of %s\n", GetVxObjectName()); } if (index < (m_columns * m_rows)) ReportError("ERROR: matrix init have too few values: %s\n", fileName); ERROR_CHECK(vxWriteMatrix(m_matrix, m_bufForAccess)); } else if (!_stricmp(ioType, "directive") && !_stricmp(fileName, "readonly")) { ERROR_CHECK(vxDirective((vx_reference)m_matrix, VX_DIRECTIVE_AMD_READ_ONLY)); } else if (!_stricmp(ioType, "ui") && !_strnicmp(fileName, "f", 1) && m_data_type == VX_TYPE_FLOAT32 && m_columns == 3 && m_rows == 3) { int id = 0; float valueR = 200.0f, valueInc = 0.5f; if (sscanf(&fileName[1], "%d,%g,%g", &id, &valueR, &valueInc) != 3) { printf("ERROR: invalid matrix UI configuration '%s'\n", fileName); return -1; } id--; GuiTrackBarInitializeMatrix((vx_reference)m_matrix, id, valueR, valueInc); GuiTrackBarProcessKey(0); // just initialize the matrix } else ReportError("ERROR: invalid matrix operation: %s\n", ioType); if (*io_params == ':') io_params++; else if (*io_params) ReportError("ERROR: unexpected character sequence in parameter specification: %s\n", io_params); } return 0; }