コード例 #1
0
bool CVxParamArray::CompareFrameBitwiseExact(size_t numItems, size_t numItemsRef, vx_uint8 * bufItems, int frameNumber, const char * fileName)
{
	// bitwise exact compare
	size_t numItemsMin = min(numItems, numItemsRef);
	size_t numMismatches = 0;
	if (numItemsMin > 0) {
		void * ptr = nullptr;
		vx_size stride = 0;
		ERROR_CHECK(vxAccessArrayRange(m_array, 0, numItems, &stride, &ptr, VX_READ_ONLY));
		for (size_t i = 0; i < numItems; i++) {
			vx_uint8 * item = vxFormatArrayPointer(ptr, i, stride);
			if (memcmp(item, bufItems + i * m_itemSize, m_itemSize) != 0) {
				numMismatches++;
			}
		}
		ERROR_CHECK(vxCommitArrayRange(m_array, 0, numItems, ptr));
	}
	numMismatches += max(numItems, numItemsRef) - numItemsMin;
	bool mismatchDetected = false;
	if (numMismatches > 0) {
		printf("ERROR: array COMPARE MISMATCHED %d/%d for %s with frame#%d of %s\n", (int)numMismatches, (int)numItems, GetVxObjectName(), frameNumber, fileName);
		mismatchDetected = true;
	}
	else {
		if (m_verbose) printf("OK: array COMPARE MATCHED for %s with frame#%d of %s\n", GetVxObjectName(), frameNumber, fileName);
	}
	return mismatchDetected;
}
コード例 #2
0
int CVxParamDistribution::CompareFrame(int frameNumber)
{
	// check if there is no user request to compare
	if (m_fileNameCompare.length() < 1) return 0;

	// make sure m_bufForRead is allocated
	if (!m_bufForCompare) NULLPTR_CHECK(m_bufForCompare = new vx_uint32[m_numBins]);

	// reading data from reference file
	char fileName[MAX_FILE_NAME_LENGTH]; sprintf(fileName, m_fileNameCompare.c_str(), frameNumber);
	FILE * fp = fopen(fileName, m_compareFileIsBinary ? "rb" : "r");
	if (!fp) {
		ReportError("ERROR: Unable to open: %s\n", fileName);
	}
	int status = ReadFileIntoBuffer(fp, m_bufForCompare);
	fclose(fp);
	if (status) ReportError("ERROR: distribution compare reference doesn't have enough data: %s\n", fileName);

	// compare and report error if mismatched
	vx_uint32 * bufRef = nullptr;
	ERROR_CHECK(vxAccessDistribution(m_distribution, (void **)&bufRef, VX_READ_ONLY));
	status = memcmp(bufRef, m_bufForCompare, m_numBins * sizeof(vx_uint32)) ? -1 : 0;
	ERROR_CHECK(vxCommitDistribution(m_distribution, bufRef));
	if (status) {
		m_compareCountMismatches++;
		printf("ERROR: distribution COMPARE MISMATCHED for %s with frame#%d of %s\n", GetVxObjectName(), frameNumber, fileName);
		if (!m_discardCompareErrors) return -1;
	}
	else {
		m_compareCountMatches++;
		if (m_verbose) printf("OK: distribution COMPARE MATCHED for %s with frame#%d of %s\n", GetVxObjectName(), frameNumber, fileName);
	}
	return 0;
}
コード例 #3
0
int CVxParamRemap::CompareFrame(int frameNumber)
{
	// check if there is no user request to compare
	if (m_fileNameCompare.length() < 1) return 0;

	// reading data from reference file
	char fileName[MAX_FILE_NAME_LENGTH]; sprintf(fileName, m_fileNameCompare.c_str(), frameNumber);
	FILE * fp = fopen(fileName, "rb");
	if (!fp) {
		ReportError("ERROR: Unable to open: %s\n", fileName);
	}
	bool mismatchDetected = false;
	int status = 0;
	for (vx_uint32 y = 0; y < m_dstHeight; y++){
		for (vx_uint32 x = 0; x < m_dstWidth; x++){
			vx_float32 xy[2];
			ERROR_CHECK(vxGetRemapPoint(m_remap, x, y, &xy[0], &xy[1]));
			vx_float32 xyRef[2];
			if (fread(xyRef, sizeof(xyRef), 1, fp) != 1) {
				status = -1;
				break;
			}
			if (fabsf(xy[0] - xyRef[0]) > m_xyErr[0] || fabsf(xy[1] - xyRef[1]) > m_xyErr[1]) {
				mismatchDetected = true;
				break;
			}
		}
		if (status || mismatchDetected)
			break;
	}
	fclose(fp);
	if (status < 0)
		ReportError("ERROR: detected EOF on remap comapre reference file: %s\n", fileName);

	if (mismatchDetected) {
		m_compareCountMismatches++;
		printf("ERROR: remap COMPARE MISMATCHED for %s with frame#%d of %s\n", GetVxObjectName(), frameNumber, fileName);
		if (!m_discardCompareErrors) return -1;
	}
	else {
		m_compareCountMatches++;
		if (m_verbose) printf("OK: remap COMPARE MATCHED for %s with frame#%d of %s\n", GetVxObjectName(), frameNumber, fileName);
	}

	return 0;
}
コード例 #4
0
int CVxParamRemap::Shutdown(void)
{
	if (m_compareCountMatches > 0 && m_compareCountMismatches == 0) {
		printf("OK: remap COMPARE MATCHED for %d frame(s) of %s\n", m_compareCountMatches, GetVxObjectName());
	}
	if (m_remap) {
		vxReleaseRemap(&m_remap);
		m_remap = nullptr;
	}
	return 0;
}
コード例 #5
0
int CVxParamArray::Shutdown(void)
{
	if (m_compareCountMatches > 0 && m_compareCountMismatches == 0) {
		printf("OK: array COMPARE MATCHED for %d frame(s) of %s\n", m_compareCountMatches, GetVxObjectName());
	}
	if (m_array) {
		vxReleaseArray(&m_array);
		m_array = nullptr;
	}
	if (m_bufForRead) {
		delete[] m_bufForRead;
		m_bufForRead = nullptr;
	}

	return 0;
}
コード例 #6
0
int CVxParamDistribution::Shutdown(void)
{
	if (m_compareCountMatches > 0 && m_compareCountMismatches == 0) {
		printf("OK: distribution COMPARE MATCHED for %d frame(s) of %s\n", m_compareCountMatches, GetVxObjectName());
	}
	if (m_distribution){
		vxReleaseDistribution(&m_distribution);
		m_distribution = nullptr;
	}
	if (m_bufForCompare) {
		delete[] m_bufForCompare;
		m_bufForCompare = nullptr;
	}
	return 0;
}
コード例 #7
0
bool CVxParamArray::CompareFrameCoord2d(size_t numItems, size_t numItemsRef, vx_uint8 * bufItems, int frameNumber, const char * fileName)
{
	FILE * fpLog = NULL;
	if (m_fileNameCompareLog.length() > 0) {
		char fileName[MAX_FILE_NAME_LENGTH]; sprintf(fileName, m_fileNameCompareLog.c_str(), frameNumber);
		fpLog = fopen(fileName, "w");
		if (!fpLog) ReportError("ERROR: Unable to create: %s\n", fileName);
		printf("OK: creating array compare output log for %s in %s\n", GetVxObjectName(), fileName);
	}

	enum { // color indices of each list for viewing
		colorIndex_match_XYexact = 0,
		colorIndex_match_XY = 1,
		colorIndex_missing_in_ref = 2,
		colorIndex_missing_in_cur = 3,
	};
	// number of keypoint counts
	size_t count_match_XYexact = 0;
	size_t count_match_XY = 0;
	size_t count_missing_in_ref = 0;
	size_t count_missing_in_cur = 0;

	// reset array list for viewing
	ResetArrayListForView();

	// get reference and actual keypoint buffers
	vx_coordinates2d_t * kpRefBase = (vx_coordinates2d_t *)m_bufForRead, *kpActualBase = nullptr;
	vx_size stride;
	if (numItems > 0) {
		ERROR_CHECK(vxAccessArrayRange(m_array, 0, numItems, &stride, (void **)&kpActualBase, VX_READ_ONLY));
	}

	// try matching reference keypoints with actual
	for (size_t j = 0; j < numItemsRef; j++) {
		vx_coordinates2d_t * kpRef = &kpRefBase[j];
		bool matched = false;
		for (size_t i = 0; i < numItems; i++) {
			vx_coordinates2d_t * kpCur = &vxArrayItem(vx_coordinates2d_t, kpActualBase, i, stride);
			if ((kpCur->x == kpRef->x) && (kpCur->y == kpRef->y)) {
				AddToArrayListForView(colorIndex_match_XYexact, kpCur->x, kpCur->y, 0.0f);
				if (fpLog) fprintf(fpLog, "MATCH-XY-EXACT       -- %5d %5d (ref:%06d) %5d %5d (cur:%06d)\n", kpRef->x, kpRef->y, (int)j, kpCur->x, kpCur->y, (int)i);
				count_match_XYexact++;
				matched = true;
			}
			else if ((abs((vx_int32)kpCur->x - (vx_int32)kpRef->x) <= m_errX) && (abs((vx_int32)kpCur->y - (vx_int32)kpRef->y) <= m_errY)) {
				AddToArrayListForView(colorIndex_match_XY, kpCur->x, kpCur->y, 0.0f);
				if (fpLog) fprintf(fpLog, "MATCH-XY             -- %5d %5d (ref:%06d) %5d %5d (cur:%06d)\n", kpRef->x, kpRef->y, (int)j, kpCur->x, kpCur->y, (int)i);
				count_match_XY++;
				matched = true;
			}
			if (matched)
				break;
		}
		if (!matched) {
			AddToArrayListForView(colorIndex_missing_in_cur, kpRef->x, kpRef->y, 0.0f);
			if (fpLog) fprintf(fpLog, "MISMATCH-WITH-CUR    -- %5d %5d (ref:%06d)\n", kpRef->x, kpRef->y, (int)j);
			count_missing_in_cur++;
		}
	}

	// try matching actual keypoints with reference
	for (size_t i = 0; i < numItems; i++) {
		vx_coordinates2d_t * kpCur = &vxArrayItem(vx_coordinates2d_t, kpActualBase, i, stride);
		bool matched = false;
		for (size_t j = 0; j < numItemsRef; j++) {
			vx_coordinates2d_t * kpRef = &kpRefBase[j];
			if ((abs((vx_int32)kpCur->x - (vx_int32)kpRef->x) <= m_errX) && (abs((vx_int32)kpCur->y - (vx_int32)kpRef->y) <= m_errY)) {
				matched = true;
				break;
			}
		}
		if (!matched) {
			AddToArrayListForView(colorIndex_missing_in_ref, kpCur->x, kpCur->y, 0.0f);
			if (fpLog) fprintf(fpLog, "MISMATCH-WITH-REF    --                          %5d %5d (cur:%06d)\n", kpCur->x, kpCur->y, (int)i);
			count_missing_in_ref++;
		}
	}

	if (numItems > 0) {
		ERROR_CHECK(vxCommitArrayRange(m_array, 0, numItems, kpActualBase));
	}

	// check for overall mismatch criteria
	size_t totalMatched = count_match_XYexact + count_match_XY;
	size_t totalMismatchesOrMissing = max(count_missing_in_ref, count_missing_in_cur);
	size_t total = totalMatched + totalMismatchesOrMissing;
	float percentMismatches = (total > 0) ? (100.0f * (float)totalMismatchesOrMissing / (float)total) : 0.0f;
	bool mismatched = false;
	if (percentMismatches > m_errMismatchPercent) {
		mismatched = true;
		printf("ERROR: array COMPARE MISMATCHED [matched %d; mismatched/missing %d (%.3f%%)] for %s with frame#%d of %s\n", (int)totalMatched, (int)totalMismatchesOrMissing, percentMismatches, GetVxObjectName(), frameNumber, fileName);
		if (fpLog) fprintf(fpLog, "ERROR: array COMPARE MISMATCHED [matched %d; mismatched/missing %d (%.3f%%)] for %s with frame#%d of %s\n", (int)totalMatched, (int)totalMismatchesOrMissing, percentMismatches, GetVxObjectName(), frameNumber, fileName);
	}
	else {
		if (m_verbose) printf("OK: array COMPARE MATCHED %.3f%% for %s with frame#%d of %s\n", 100.0f - percentMismatches, GetVxObjectName(), frameNumber, fileName);
		if (fpLog) fprintf(fpLog, "OK: array COMPARE MATCHED %.3f%% for %s with frame#%d of %s\n", 100.0f - percentMismatches, GetVxObjectName(), frameNumber, fileName);
	}

	if (fpLog) fclose(fpLog);
	return mismatched;
}
コード例 #8
0
int CVxParamTensor::CompareFrame(int frameNumber)
{
	// check if there is no user request to compare
	if (m_fileNameCompare.length() < 1) return 0;

	// reading data from reference file
	char fileName[MAX_FILE_NAME_LENGTH]; sprintf(fileName, m_fileNameCompare.c_str(), frameNumber);
	if(!_stricmp(fileName + strlen(fileName) - 4, ".dat")) {
		ReportError("ERROR: read from .dat files not supported: %s\n", fileName);
	}
	FILE * fp = fopen(fileName, m_compareFileIsBinary ? "rb" : "r");
	if (!fp) {
		ReportError("ERROR: Unable to open: %s\n", fileName);
	}
	if (fread(m_data, 1, m_size, fp) != m_size)
		ReportError("ERROR: not enough data (%d bytes) in %s\n", (vx_uint32)m_size, fileName);
	fclose(fp);

	// compare
	vx_map_id map_id;
	vx_size stride[MAX_TENSOR_DIMENSIONS];
	vx_uint8 * ptr;
	vx_status status = vxMapTensorPatch(m_tensor, m_num_of_dims, nullptr, nullptr, &map_id, stride, (void **)&ptr, VX_READ_ONLY, VX_MEMORY_TYPE_HOST, 0);
	if (status != VX_SUCCESS)
		ReportError("ERROR: vxMapTensorPatch: read failed (%d)\n", status);

	bool mismatchDetected = false;
	if (m_data_type == VX_TYPE_INT16) {
		vx_int32 maxError = 0;
		vx_int64 sumError = 0;
		for (vx_size d3 = 0; d3 < m_dims[3]; d3++) {
			for (vx_size d2 = 0; d2 < m_dims[2]; d2++) {
				for (vx_size d1 = 0; d1 < m_dims[1]; d1++) {
					vx_size roffset = m_stride[3] * d3 + m_stride[2] * d2 + m_stride[1] * d1;
					vx_size doffset = stride[3] * d3 + stride[2] * d2 + stride[1] * d1;
					const vx_int16 * buf1 = (const vx_int16 *)(((vx_uint8 *)ptr) + doffset);
					const vx_int16 * buf2 = (const vx_int16 *)(m_data + roffset);
					for (vx_size d0 = 0; d0 < m_dims[0]; d0++) {
						vx_int32 v1 = buf1[d0];
						vx_int32 v2 = buf2[d0];
						vx_int32 d = v1 - v2;
						d = (d < 0) ? -d : d;
						maxError = (d > maxError) ? d : maxError;
						sumError += d * d;
					}
				}
			}
		}
		vx_size count = m_dims[0] * m_dims[1] * m_dims[2] * m_dims[3];
		float avgError = (float)sumError / (float)count;
		mismatchDetected = true;
		if (((float)maxError <= m_maxErrorLimit) && ((float)avgError <= m_avgErrorLimit))
		    mismatchDetected = false;
		if (mismatchDetected)
			printf("ERROR: tensor COMPARE MISMATCHED [max-err: %d] [avg-err: %.6f] for %s with frame#%d of %s\n", maxError, avgError, GetVxObjectName(), frameNumber, fileName);
		else if (m_verbose)
			printf("OK: tensor COMPARE MATCHED [max-err: %d] [avg-err: %.6f] for %s with frame#%d of %s\n", maxError, avgError, GetVxObjectName(), frameNumber, fileName);
	}
	else if (m_data_type == VX_TYPE_FLOAT32) {
		vx_float32 maxError = 0;
		vx_float64 sumError = 0;
		for (vx_size d3 = 0; d3 < m_dims[3]; d3++) {
			for (vx_size d2 = 0; d2 < m_dims[2]; d2++) {
				for (vx_size d1 = 0; d1 < m_dims[1]; d1++) {
					vx_size roffset = m_stride[3] * d3 + m_stride[2] * d2 + m_stride[1] * d1;
					vx_size doffset = stride[3] * d3 + stride[2] * d2 + stride[1] * d1;
					const vx_float32 * buf1 = (const vx_float32 *)(((vx_uint8 *)ptr) + doffset);
					const vx_float32 * buf2 = (const vx_float32 *)(m_data + roffset);
					for (vx_size d0 = 0; d0 < m_dims[0]; d0++) {
						vx_float32 v1 = buf1[d0];
						vx_float32 v2 = buf2[d0];
						vx_float32 d = v1 - v2;
						d = (d < 0) ? -d : d;
						maxError = (d > maxError) ? d : maxError;
						sumError += d * d;
					}
				}
			}
		}
		vx_size count = m_dims[0] * m_dims[1] * m_dims[2] * m_dims[3];
		float avgError = (float)sumError / (float)count;
		mismatchDetected = true;
		if ((maxError <= m_maxErrorLimit) && (avgError <= m_avgErrorLimit))
		    mismatchDetected = false;
		if (mismatchDetected)
			printf("ERROR: tensor COMPARE MISMATCHED [max-err: %.6f] [avg-err: %.6f] for %s with frame#%d of %s\n", maxError, avgError, GetVxObjectName(), frameNumber, fileName);
		else if (m_verbose)
			printf("OK: tensor COMPARE MATCHED [max-err: %.6f] [avg-err: %.6f] for %s with frame#%d of %s\n", maxError, avgError, GetVxObjectName(), frameNumber, fileName);
	}
	else if (m_data_type == VX_TYPE_FLOAT16) {
		vx_float32 maxError = 0;
		vx_float64 sumError = 0;
		for (vx_size d3 = 0; d3 < m_dims[3]; d3++) {
			for (vx_size d2 = 0; d2 < m_dims[2]; d2++) {
				for (vx_size d1 = 0; d1 < m_dims[1]; d1++) {
					vx_size roffset = m_stride[3] * d3 + m_stride[2] * d2 + m_stride[1] * d1;
					vx_size doffset = stride[3] * d3 + stride[2] * d2 + stride[1] * d1;
					const vx_uint16 * buf1 = (const vx_uint16 *)(((vx_uint8 *)ptr) + doffset);
					const vx_uint16 * buf2 = (const vx_uint16 *)(m_data + roffset);
					for (vx_size d0 = 0; d0 < m_dims[0]; d0++) {
						vx_uint16 h1 = buf1[d0];
						vx_uint16 h2 = buf2[d0];
						vx_uint32 d1 = ((h1 & 0x8000) << 16) | (((h1 & 0x7c00) + 0x1c000) << 13) | ((h1 & 0x03ff) << 13);
						vx_uint32 d2 = ((h2 & 0x8000) << 16) | (((h2 & 0x7c00) + 0x1c000) << 13) | ((h2 & 0x03ff) << 13);
						vx_float32 v1 = *(float *)&d1;
						vx_float32 v2 = *(float *)&d2;
						vx_float32 d = v1 - v2;
						d = (d < 0) ? -d : d;
						maxError = (d > maxError) ? d : maxError;
						sumError += d * d;
					}
				}
			}
		}
		vx_size count = m_dims[0] * m_dims[1] * m_dims[2] * m_dims[3];
		float avgError = (float)sumError / (float)count;
		mismatchDetected = true;
		if ((maxError <= m_maxErrorLimit) && (avgError <= m_avgErrorLimit))
		    mismatchDetected = false;
		if (mismatchDetected)
			printf("ERROR: tensor COMPARE MISMATCHED [max-err: %.6f] [avg-err: %.6f] for %s with frame#%d of %s\n", maxError, avgError, GetVxObjectName(), frameNumber, fileName);
		else if (m_verbose)
			printf("OK: tensor COMPARE MATCHED [max-err: %.6f] [avg-err: %.6f] for %s with frame#%d of %s\n", maxError, avgError, GetVxObjectName(), frameNumber, fileName);
	}
	else {
		for (vx_size d3 = 0; d3 < m_dims[3]; d3++) {
			for (vx_size d2 = 0; d2 < m_dims[2]; d2++) {
				for (vx_size d1 = 0; d1 < m_dims[1]; d1++) {
					vx_size roffset = m_stride[3] * d3 + m_stride[2] * d2 + m_stride[1] * d1;
					vx_size doffset = stride[3] * d3 + stride[2] * d2 + stride[1] * d1;
					if (memcpy(((vx_uint8 *)ptr) + doffset, m_data + roffset, stride[0] * m_dims[0])) {
						mismatchDetected = true;
						break;
					}
				}
				if (mismatchDetected)
					break;
			}
			if (mismatchDetected)
				break;
		}
		if (mismatchDetected)
			printf("ERROR: tensor COMPARE MISMATCHED for %s with frame#%d of %s\n", GetVxObjectName(), frameNumber, fileName);
		else if (m_verbose) 
			printf("OK: tensor COMPARE MATCHED for %s with frame#%d of %s\n", GetVxObjectName(), frameNumber, fileName);
	}

	status = vxUnmapTensorPatch(m_tensor, map_id);
	if (status != VX_SUCCESS)
		ReportError("ERROR: vxUnmapTensorPatch: read failed (%d)\n", status);

	// report error if mismatched
	if (mismatchDetected) {
		m_compareCountMismatches++;
		if (!m_discardCompareErrors) return -1;
	}
	else {
		m_compareCountMatches++;
	}

	return 0;
}
コード例 #9
0
int CVxParamTensor::Shutdown(void)
{
	if (m_compareCountMatches > 0 && m_compareCountMismatches == 0) {
		printf("OK: tensor COMPARE MATCHED for %d frame(s) of %s\n", m_compareCountMatches, GetVxObjectName());
	}
	if (m_tensor) {
		vxReleaseTensor(&m_tensor);
		m_tensor = nullptr;
	}
	if (m_data) {
		delete[] m_data;
		m_data = nullptr;
	}
	if (m_memory_type == VX_MEMORY_TYPE_HOST) {
		for (vx_size active_handle = 0; active_handle < m_num_handles; active_handle++) {
			if (m_memory_handle[active_handle])
				free(m_memory_handle[active_handle]);
			m_memory_handle[active_handle] = nullptr;
		}
	}
#if ENABLE_OPENCL
	else if (m_memory_type == VX_MEMORY_TYPE_OPENCL) {
		for (vx_size active_handle = 0; active_handle < m_num_handles; active_handle++) {
			if (m_memory_handle[active_handle]) {
				int err = clReleaseMemObject((cl_mem)m_memory_handle[active_handle]);
				if (err)
					ReportError("ERROR: clReleaseMemObject(*) failed (%d)\n", err);
			}
			m_memory_handle[active_handle] = nullptr;
		}
	}
#endif
	return 0;
}
コード例 #10
0
ファイル: vxMatrix.cpp プロジェクト: Badiboy/amdovx-core
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;
}
コード例 #11
0
ファイル: vxMatrix.cpp プロジェクト: Badiboy/amdovx-core
int CVxParamMatrix::Shutdown(void)
{
	if (m_compareCountMatches > 0 && m_compareCountMismatches == 0) {
		printf("OK: matrix COMPARE MATCHED for %d frame(s) of %s\n", m_compareCountMatches, GetVxObjectName());
	}
	GuiTrackBarShutdown((vx_reference)m_matrix);
	if (m_matrix) {
		vxReleaseMatrix(&m_matrix);
		m_matrix = nullptr;
	}
	if (m_bufForAccess) {
		delete[] m_bufForAccess;
		m_bufForAccess = nullptr;
	}
	return 0;
}
コード例 #12
0
ファイル: vxMatrix.cpp プロジェクト: Badiboy/amdovx-core
int CVxParamMatrix::CompareFrame(int frameNumber)
{
	// check if there is no user request to compare
	if (m_fileNameCompare.length() < 1) return 0;

	// make sure buffer has been allocated and read the matrix data
	if (!m_bufForAccess) NULLPTR_CHECK(m_bufForAccess = new vx_uint8[m_size]);
	ERROR_CHECK(vxReadMatrix(m_matrix, m_bufForAccess));

	// reading data from reference file
	char fileName[MAX_FILE_NAME_LENGTH]; sprintf(fileName, m_fileNameCompare.c_str(), frameNumber);
	FILE * fp = fopen(fileName, m_compareFileIsBinary ? "rb" : "r");
	if (!fp) {
		ReportError("ERROR: Unable to open: %s\n", fileName);
	}
	bool mismatchDetected = false;
	int status = 0, errTolerance = (int)m_errTolerance;
	vx_size itemsize = m_size / (m_columns * m_rows);
	for (vx_size index = 0; index < (m_columns * m_rows); index++) {
		union {
			vx_int32 i32; 
			vx_float32 f32; 
			vx_uint8 u8;
		} item;
		if (m_compareFileIsBinary) {
			if (fread(&item, itemsize, 1, fp) != 1) {
				status = -1;
				break;
			}
		}
		else {
			if (m_data_type == VX_TYPE_INT32 || m_data_type == VX_TYPE_UINT8) {
				if (fscanf(fp, "%i", &item.i32) != 1) {
					status = -1;
					break;
				}
			}
			else if (m_data_type == VX_TYPE_FLOAT32) {
				if (fscanf(fp, "%g", &item.f32) != 1) {
					status = -1;
					break;
				}
			}
			else ReportError("ERROR: matrix ascii compare option not support for data_type of %s\n", GetVxObjectName());
		}
		if (m_data_type == VX_TYPE_INT32) {
			if (abs(item.i32 - ((vx_int32 *)m_bufForAccess)[index]) > errTolerance)
				mismatchDetected = true;
		}
		else if (m_data_type == VX_TYPE_FLOAT32) {
			if (fabsf(item.f32 - ((vx_float32 *)m_bufForAccess)[index]) > m_errTolerance)
				mismatchDetected = true;
		}
		else if (m_data_type == VX_TYPE_UINT8) {
			if (abs((int)item.u8 - (int)((vx_uint8 *)m_bufForAccess)[index]) > errTolerance)
				mismatchDetected = true;
		}
		if (mismatchDetected)
			break;
	}
	fclose(fp);
	if (status < 0)
		ReportError("ERROR: detected EOF on matrix comapre reference file: %s\n", fileName);

	if (mismatchDetected) {
		m_compareCountMismatches++;
		printf("ERROR: matrix COMPARE MISMATCHED for %s with frame#%d of %s\n", GetVxObjectName(), frameNumber, fileName);
		if (!m_discardCompareErrors) return -1;
	}
	else {
		m_compareCountMatches++;
		if (m_verbose) printf("OK: matrix COMPARE MATCHED for %s with frame#%d of %s\n", GetVxObjectName(), frameNumber, fileName);
	}

	return 0;
}
コード例 #13
0
ファイル: vxMatrix.cpp プロジェクト: Badiboy/amdovx-core
int CVxParamMatrix::WriteFrame(int frameNumber)
{
	// check if there is no user request to write
	if (m_fileNameWrite.length() < 1) return 0;

	// make sure buffer has been allocated and read the matrix data
	if (!m_bufForAccess) NULLPTR_CHECK(m_bufForAccess = new vx_uint8[m_size]);
	ERROR_CHECK(vxReadMatrix(m_matrix, m_bufForAccess));

	// write data to output file
	char fileName[MAX_FILE_NAME_LENGTH]; sprintf(fileName, m_fileNameWrite.c_str(), frameNumber);
	FILE * fp = fopen(fileName, m_writeFileIsBinary ? "wb" : "w");
	if (!fp) ReportError("ERROR: Unable to create: %s\n", fileName);
	if (m_writeFileIsBinary) {
		fwrite(m_bufForAccess, 1, m_size, fp);
	}
	else {
		for (vx_size index = 0; index < m_columns * m_rows; index++) {
			if (m_data_type == VX_TYPE_INT32) fprintf(fp, "%d ", ((vx_int32 *)m_bufForAccess)[index]);
			else if (m_data_type == VX_TYPE_FLOAT32) fprintf(fp, "%g ", ((vx_float32 *)m_bufForAccess)[index]);
			else if (m_data_type == VX_TYPE_UINT8) fprintf(fp, "%d ", ((vx_uint8 *)m_bufForAccess)[index]);
			else ReportError("ERROR: matrix ascii write option not support for data_type of %s\n", GetVxObjectName());
		}
		fprintf(fp, "\n");
	}
	fclose(fp);

	return 0;
}
コード例 #14
0
ファイル: vxMatrix.cpp プロジェクト: Badiboy/amdovx-core
int CVxParamMatrix::ReadFrame(int frameNumber)
{
	// check if there is no user request to read
	if (m_fileNameRead.length() < 1) return 0;

	// make sure buffer has been allocated
	if (!m_bufForAccess) NULLPTR_CHECK(m_bufForAccess = new vx_uint8[m_size]);

	// for single frame reads, there is no need to read it again
	// as it is already read into the object
	if (!m_fileNameForReadHasIndex && frameNumber != m_captureFrameStart) {
		return 0;
	}

	// reading data from input file
	char fileName[MAX_FILE_NAME_LENGTH]; sprintf(fileName, m_fileNameRead.c_str(), frameNumber);
	FILE * fp = fopen(fileName, m_readFileIsBinary ? "rb" : "r");
	if (!fp) {
		if (frameNumber == m_captureFrameStart) {
			ReportError("ERROR: Unable to open: %s\n", fileName);
		}
		else {
			return 1; // end of sequence detected for multiframe sequences
		}
	}
	int status = 0;
	if (m_readFileIsBinary) {
		if (fread(m_bufForAccess, 1, m_size, fp) != m_size)
			status = -1;
	}
	else {
		for (vx_size index = 0; index < (m_columns * m_rows); index++) {
			if (m_data_type == VX_TYPE_INT32 || m_data_type == VX_TYPE_UINT8) {
				vx_uint32 value;
				if (fscanf(fp, "%i", &value) != 1) {
					status = -1;
					break;
				}
				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) {
				if (fscanf(fp, "%g", &((vx_float32 *)m_bufForAccess)[index]) != 1) {
					status = -1;
					break;
				}
			}
			else ReportError("ERROR: matrix ascii read option not support for data_type of %s\n", GetVxObjectName());
		}
	}
	ERROR_CHECK(vxWriteMatrix(m_matrix, m_bufForAccess));
	fclose(fp);
	if (status < 0)
		ReportError("ERROR: detected EOF on matrix input file: %s\n", fileName);

	return status;
}