void region_init(void) { // VALGRIND_DO_QUICK_LEAK_CHECK; // fprintf(stderr, "## region_init\n"); static int initialized = 0; if ( initialized ) return; else { #ifdef STAGGER_RSTART rstart = -64; /* Save 64 bytes of memory! (sometimes ;-)) */ #endif init_pages(); permanent = newregion(); if (getenv("REGIONSTATS")) benchmark_init(); #ifdef DEBUG_RALLOC atexit(memusage); #endif } initialized = 1; // VALGRIND_DO_QUICK_LEAK_CHECK; }
int main(int argc, char** argv) { MPI_Init(&argc, &argv); const size_t n = atoi(argv[1]); const size_t p = atoi(argv[2]); const procs_t procs = {n, p}; const size_t t = atoi(argv[3]); const size_t x = atoi(argv[4]); const size_t y = atoi(argv[5]); const size_t z = atoi(argv[6]); const size_t ndims = 4; const size_t dgeom[4] = {t, x, y, z}; const size_t bgeom[4] = {1, x / n, y / p, z}; const size_t cgeom[4] = {1, x / n, y / p, z}; const char* testfn = "./test.nc"; const io_mode_t io_mode = NC_INDEPENDENT; const int par_access = NC_CHUNKED; const bool is_unlimited = 0; benchmark_t bm; benchmark_init(&bm); benchmark_setup(&bm, procs, ndims, dgeom, bgeom, cgeom, testfn, io_mode, par_access, is_unlimited); benchmark_run(&bm); benchmark_destroy(&bm); MPI_Finalize(); return 0; }
AUD_Int32s perf_dtw_mfcc_vad() { char inputPath[256] = { 0, }; char keywordPath[256] = { 0, }; AUD_Double threshold, minThreshold, maxThreshold, stepThreshold; AUD_Bool isRecognized = AUD_FALSE; AUD_Int32s data; AUD_Error error = AUD_ERROR_NONE; setbuf( stdin, NULL ); AUDLOG( "pls give template wav stream's path:\n" ); keywordPath[0] = '\0'; data = scanf( "%s", keywordPath ); AUDLOG( "template path is: %s\n", keywordPath ); setbuf( stdin, NULL ); AUDLOG( "pls give test wav stream's path:\n" ); inputPath[0] = '\0'; data = scanf( "%s", inputPath ); AUDLOG( "test stream path is: %s\n", inputPath ); setbuf( stdin, NULL ); AUDLOG( "pls give lowest test threshold:\n" ); data = scanf( "%lf", &minThreshold ); AUDLOG( "lowest threshold is: %.2f\n", minThreshold ); setbuf( stdin, NULL ); AUDLOG( "pls give max test threshold:\n" ); data = scanf( "%lf", &maxThreshold ); AUDLOG( "max threshold is: %.2f\n", maxThreshold ); setbuf( stdin, NULL ); AUDLOG( "pls give test threshold step:\n" ); data = scanf( "%lf", &stepThreshold ); AUDLOG( "threshold step is: %.2f\n", stepThreshold ); AUDLOG( "\n\n" ); // file & directory operation, linux dependent entry *pEntry = NULL; dir *pDir = NULL; entry *pKeywordEntry = NULL; dir *pKeywordDir = NULL; AUD_Int32s i, j; AUD_Feature keywordFeature; AUD_Int32s keywordSampleNum = 0; AUD_Int32s keywordWinNum = 0; AUD_Int8s keywordFile[256] = { 0, }; AUD_Int8s keywordName[256] = { 0, }; AUD_Int32s keywordID = 0; AUD_DTWSession dtwSession; AUD_Double score = 0.; AUD_Int32s sampleNum; AUD_Int32s keywordBufLen = 0; AUD_Int16s *pKeywordBuf = NULL; AUD_Int32s bufLen = 0; AUD_Int16s *pBuf = NULL; AUD_Int32s ret; // init performance benchmark void *hBenchmark = NULL; char logName[256] = { 0, }; snprintf( logName, 256, "dtw-mfcc-vad-%d-%d-%d-%d", WOV_DTW_TYPE, WOV_DISTANCE_METRIC, WOV_DTWTRANSITION_STYLE, WOV_DTWSCORING_METHOD ); ret = benchmark_init( &hBenchmark, (AUD_Int8s*)logName, keywords, sizeof(keywords) / sizeof(keywords[0]) ); AUD_ASSERT( ret == 0 ); for ( threshold = minThreshold; threshold < maxThreshold + stepThreshold; threshold += stepThreshold ) { int frameStride = 0; ret = benchmark_newthreshold( hBenchmark, threshold ); AUD_ASSERT( ret == 0 ); AUDLOG( "***********************************************\n" ); AUDLOG( "keyword training start...\n" ); pKeywordDir = openDir( (const char*)keywordPath ); keywordID = 0; while ( ( pKeywordEntry = scanDir( pKeywordDir ) ) ) { // train keyword AUD_Summary fileSummary; snprintf( (char*)keywordFile, 256, "%s/%s", (const char*)keywordPath, pKeywordEntry->name ); ret = parseWavFromFile( keywordFile, &fileSummary ); if ( ret < 0 ) { continue; } AUD_ASSERT( fileSummary.channelNum == CHANNEL_NUM && fileSummary.bytesPerSample == BYTES_PER_SAMPLE && fileSummary.sampleRate == SAMPLE_RATE ); keywordBufLen = fileSummary.dataChunkBytes + 100; pKeywordBuf = (AUD_Int16s*)calloc( keywordBufLen, 1 ); AUD_ASSERT( pKeywordBuf ); keywordSampleNum = readWavFromFile( keywordFile, pKeywordBuf, keywordBufLen ); if ( keywordSampleNum < 0 ) { continue; } // front end processing // pre-emphasis sig_preemphasis( pKeywordBuf, pKeywordBuf, keywordSampleNum ); for ( j = 0; j * FRAME_STRIDE + FRAME_LEN <= keywordSampleNum; j++ ) { ; } frameStride = FRAME_STRIDE; AUDLOG( "pattern[%d: %s] valid frame number[%d]\n", keywordID, keywordFile, j ); keywordWinNum = j; keywordFeature.featureMatrix.rows = keywordWinNum - MFCC_DELAY; keywordFeature.featureMatrix.cols = MFCC_FEATDIM; keywordFeature.featureMatrix.dataType = AUD_DATATYPE_INT32S; ret = createMatrix( &(keywordFeature.featureMatrix) ); AUD_ASSERT( ret == 0 ); keywordFeature.featureNorm.len = keywordWinNum - MFCC_DELAY; keywordFeature.featureNorm.dataType = AUD_DATATYPE_INT64S; ret = createVector( &(keywordFeature.featureNorm) ); AUD_ASSERT( ret == 0 ); void *hTemplateMfccHandle = NULL; // init mfcc handle error = mfcc16s32s_init( &hTemplateMfccHandle, FRAME_LEN, WINDOW_TYPE, MFCC_ORDER, frameStride, SAMPLE_RATE, COMPRESS_TYPE ); AUD_ASSERT( error == AUD_ERROR_NONE ); // calc MFCC feature error = mfcc16s32s_calc( hTemplateMfccHandle, pKeywordBuf, keywordSampleNum, &keywordFeature ); AUD_ASSERT( error == AUD_ERROR_NONE ); // deinit mfcc handle error = mfcc16s32s_deinit( &hTemplateMfccHandle ); AUD_ASSERT( error == AUD_ERROR_NONE ); strncpy( (char*)keywordName, pKeywordEntry->name, 255 ); ret = benchmark_newtemplate( hBenchmark, keywordName ); AUD_ASSERT( ret == 0 ); keywordID++; keywordBufLen = 0; free( pKeywordBuf ); pKeywordBuf = NULL; AUDLOG( "keyword training finish...\n" ); // recognize pEntry = NULL; pDir = NULL; pDir = openDir( (const char*)inputPath ); while ( ( pEntry = scanDir( pDir ) ) ) { AUD_Int8s inputStream[256] = { 0, }; void *hMfccHandle = NULL; AUD_Summary fileSummary; snprintf( (char*)inputStream, 256, "%s/%s", (const char*)inputPath, pEntry->name ); ret = parseWavFromFile( inputStream, &fileSummary ); if ( ret < 0 ) { continue; } AUD_ASSERT( fileSummary.channelNum == CHANNEL_NUM && fileSummary.bytesPerSample == BYTES_PER_SAMPLE && fileSummary.sampleRate == SAMPLE_RATE ); AUDLOG( "input stream: %s\n", inputStream ); bufLen = fileSummary.dataChunkBytes; pBuf = (AUD_Int16s*)malloc( bufLen + 100 ); AUD_ASSERT( pBuf ); sampleNum = readWavFromFile( inputStream, pBuf, bufLen ); AUD_ASSERT( sampleNum > 0 ); // VAD AUD_Int16s *pValidBuf = (AUD_Int16s*)calloc( bufLen, 1 ); AUD_ASSERT( pValidBuf ); AUD_Int16s *pSpeechFlag = (AUD_Int16s*)calloc( ( sampleNum / VAD_FRAME_LEN ) + 1, sizeof( AUD_Int16s ) ); AUD_ASSERT( pSpeechFlag ); void *hVadHandle = NULL; ret = sig_vadinit( &hVadHandle, pValidBuf, pSpeechFlag, bufLen, -1, -1 ); AUD_ASSERT( ret == 0 ); AUD_Int32s start = -1; for ( i = 0; i * VAD_FRAME_LEN + FRAME_LEN <= sampleNum; i++ ) { ret = sig_vadupdate( hVadHandle, pBuf + i * VAD_FRAME_LEN, &start ); if ( ret == 0 ) { continue; } else { break; } } if ( ret == 0 ) { continue; } AUD_Int32s validSampleNum = ret; sig_vaddeinit( &hVadHandle ); #if 1 char vadFile[256] = { 0, }; snprintf( vadFile, 255, "./vaded/%s", pEntry->name ); ret = writeWavToFile( (AUD_Int8s*)vadFile, pValidBuf + start, validSampleNum ); AUD_ASSERT( ret == 0 ); #endif // de-noise AUD_Int16s *pCleanBuf = (AUD_Int16s*)calloc( (validSampleNum + start) * BYTES_PER_SAMPLE, 1 ); AUD_ASSERT( pCleanBuf ); AUD_Int32s cleanLen = denoise_mmse( pValidBuf, pCleanBuf, (validSampleNum + start) ); #if 1 char cleanFile[256] = { 0, }; snprintf( cleanFile, 255, "./clean/%s", pEntry->name ); ret = writeWavToFile( (AUD_Int8s*)cleanFile, pCleanBuf, cleanLen ); AUD_ASSERT( ret == 0 ); #endif // front end processing // pre-emphasis sig_preemphasis( pCleanBuf, pCleanBuf, cleanLen ); for ( j = 0; j * FRAME_STRIDE + FRAME_LEN <= cleanLen; j++ ) { ; } frameStride = FRAME_LEN; bufLen = 0; free( pBuf ); pBuf = NULL; free( pValidBuf ); pValidBuf = NULL; free( pSpeechFlag ); pSpeechFlag = NULL; AUD_Feature inFeature; inFeature.featureMatrix.rows = j - MFCC_DELAY; inFeature.featureMatrix.cols = MFCC_FEATDIM; inFeature.featureMatrix.dataType = AUD_DATATYPE_INT32S; ret = createMatrix( &(inFeature.featureMatrix) ); AUD_ASSERT( ret == 0 ); inFeature.featureNorm.len = j - MFCC_DELAY; inFeature.featureNorm.dataType = AUD_DATATYPE_INT64S; ret = createVector( &(inFeature.featureNorm) ); AUD_ASSERT( ret == 0 ); // init mfcc handle error = mfcc16s32s_init( &hMfccHandle, FRAME_LEN, WINDOW_TYPE, MFCC_ORDER, frameStride, SAMPLE_RATE, COMPRESS_TYPE ); AUD_ASSERT( error == AUD_ERROR_NONE ); error = mfcc16s32s_calc( hMfccHandle, pCleanBuf, cleanLen, &inFeature ); AUD_ASSERT( error == AUD_ERROR_NONE ); // init dtw match dtwSession.dtwType = WOV_DTW_TYPE; dtwSession.distType = WOV_DISTANCE_METRIC; dtwSession.transitionType = WOV_DTWTRANSITION_STYLE; error = dtw_initsession( &dtwSession, &keywordFeature, inFeature.featureMatrix.rows ); AUD_ASSERT( error == AUD_ERROR_NONE ); error = dtw_updatefrmcost( &dtwSession, &inFeature ); AUD_ASSERT( error == AUD_ERROR_NONE ); error = dtw_match( &dtwSession, WOV_DTWSCORING_METHOD, &score, NULL ); AUD_ASSERT( error == AUD_ERROR_NONE ); error = dtw_deinitsession( &dtwSession ); AUD_ASSERT( error == AUD_ERROR_NONE ); // deinit mfcc handle error = mfcc16s32s_deinit( &hMfccHandle ); AUD_ASSERT( error == AUD_ERROR_NONE ); ret = destroyMatrix( &(inFeature.featureMatrix) ); AUD_ASSERT( ret == 0 ); ret = destroyVector( &(inFeature.featureNorm) ); AUD_ASSERT( ret == 0 ); AUDLOG( "score: %.2f\n", score ); isRecognized = AUD_FALSE; if ( score <= threshold ) { isRecognized = AUD_TRUE; } // insert log entry ret = benchmark_additem( hBenchmark, (AUD_Int8s*)pEntry->name, score, isRecognized ); AUD_ASSERT( ret == 0 ); cleanLen = 0; free( pCleanBuf ); pCleanBuf = NULL; } closeDir( pDir ); pDir = NULL; ret = benchmark_finalizetemplate( hBenchmark ); AUD_ASSERT( ret == 0 ); ret = destroyMatrix( &(keywordFeature.featureMatrix) ); AUD_ASSERT( ret == 0 ); ret = destroyVector( &(keywordFeature.featureNorm) ); AUD_ASSERT( ret == 0 ); } closeDir( pKeywordDir ); pKeywordDir = NULL; ret = benchmark_finalizethreshold( hBenchmark ); AUD_ASSERT( ret == 0 ); } ret = benchmark_free( &hBenchmark ); AUD_ASSERT( ret == 0 ); AUDLOG( "DTW-MFCC VAD Benchmark finished\n" ); return 0; }
int main(int argc, char ** argv){ MPI_Init(&argc, &argv); // Default values struct args args; args.procs.nn = 0; args.procs.ppn = 0; args.dgeom_size = 0; args.dgeom = NULL; args.bgeom_size = 0; args.bgeom = NULL; args.cgeom_size = 0; args.cgeom = NULL; args.testfn = NULL; args.write_test = 0; args.read_test = 0; args.report_type = REPORT_HUMAN; args.par_access = NC_INDEPENDENT; args.is_unlimited = 0; args.verify = 0; args.fill_value = 0; char * dg = NULL, * bg = NULL, *cg = NULL, *iot = "ind", *xf = "human"; option_help options [] = { {'n' , "nn" , "Number of nodes" , OPTION_OPTIONAL_ARGUMENT , 'd' , & args.procs.nn} , {'p' , "ppn" , "Number of processes" , OPTION_OPTIONAL_ARGUMENT , 'd' , & args.procs.ppn} , {'d' , "data-geometry" , "Data geometry (t:x:y:z)" , OPTION_OPTIONAL_ARGUMENT , 's' , & dg} , {'b' , "block-geometry" , "Block geometry (t:x:y:z)" , OPTION_OPTIONAL_ARGUMENT , 's' , & bg} , {'c' , "chunk-geometry" , "Chunk geometry (t:x:y:z|auto)" , OPTION_OPTIONAL_ARGUMENT , 's' , & cg} , {'r' , "read" , "Enable read benchmark" , OPTION_FLAG , 'd' , & args.read_test} , {'w' , "write" , "Enable write benchmark" , OPTION_FLAG , 'd' , & args.write_test} , {'t' , "io-type" , "Independent / Collective I/O (ind|coll)" , OPTION_OPTIONAL_ARGUMENT , 's' , & iot} , {'u' , "unlimited" , "Enable unlimited time dimension" , OPTION_FLAG , 'd' , & args.is_unlimited} , {'f' , "testfile" , "Filename of the testfile" , OPTION_OPTIONAL_ARGUMENT , 's' , & args.testfn} , {'x' , "output-format" , "Output-Format (parser|human)" , OPTION_OPTIONAL_ARGUMENT , 's' , & xf} , {'F' , "use-fill-value" , "Write a fill value" , OPTION_FLAG , 'd', & args.fill_value} , {0 , "verify" , "Verify that the data read is correct (reads the data again)", OPTION_FLAG , 'd' , & args.verify} , LAST_OPTION }; int rank; MPI_Comm_rank(MPI_COMM_WORLD, & rank); // check the correctness of the options only for rank 0 if (rank == 0){ printf("Benchtool (datatype: %s) \n", xstr(DATATYPE)); parseOptions(argc, argv, options); } MPI_Barrier(MPI_COMM_WORLD); if (rank != 0){ parseOptions(argc, argv, options); } parse_dims(dg, &args.dgeom, &args.dgeom_size); parse_dims(bg, &args.bgeom, &args.bgeom_size); if ((0 == strcmp(iot, "c")) | (0 == strcmp(iot, "coll")) | (0 == strcmp(iot,"collective"))) { args.par_access = NC_COLLECTIVE; } else if ((0 == strcmp(iot, "i")) | (0 == strcmp(iot, "ind")) | (0 == strcmp(iot, "independent"))) { args.par_access = NC_INDEPENDENT; } else { FATAL_ERR("Unsupported parallel access type %s\n", xf); } if (0 == strcmp(xf, "parser")) { args.report_type = REPORT_PARSER; }else if (0 == strcmp(xf, "human")) { args.report_type = REPORT_HUMAN; }else{ FATAL_ERR("Unsupported report type %s\n", xf); } if (0 == args.procs.nn) { char *end = NULL; const char* env = getenv("SLURM_NNODES"); if (NULL != env) { args.procs.nn = strtol(env, &end, 10); } if (0 == args.procs.nn) { args.procs.nn = 1; } } if (0 == args.procs.ppn) { char *end = NULL; const char* env = getenv("SLURM_NTASKS_PER_NODE"); if (NULL != env) { args.procs.ppn = strtol(env, &end, 10); } if (0 == args.procs.ppn) { args.procs.ppn = 1; } } if (NULL == args.testfn) { const char* testfn = "./testfn.nc"; args.testfn = (char*)malloc(sizeof(*args.testfn) * strlen(testfn) + 1); strcpy(args.testfn, testfn); } if (NULL == args.dgeom) { args.dgeom_size = NDIMS; args.dgeom = (size_t*)malloc(sizeof(*args.dgeom) * args.dgeom_size); args.dgeom[DT] = 100; args.dgeom[DX] = args.procs.nn * 100; args.dgeom[DY] = args.procs.ppn * 100; args.dgeom[DZ] = 10; } if (NDIMS != args.dgeom_size) { FATAL_ERR("Found %zu dimensions (expected %d).\n", args.dgeom_size, NDIMS); } // Automatic block layout if (NULL == args.bgeom) { args.bgeom_size = args.dgeom_size; args.bgeom = (size_t*)malloc(sizeof(*args.bgeom) * args.bgeom_size); args.bgeom[DT] = 1; args.bgeom[DX] = args.dgeom[DX] / args.procs.nn; args.bgeom[DY] = args.dgeom[DY] / args.procs.ppn; args.bgeom[DZ] = args.dgeom[DZ]; } if (cg != NULL && 0 == strcmp(cg, "auto")) { args.cgeom_size = args.bgeom_size; args.cgeom = (size_t*)malloc(sizeof(*args.cgeom) * args.cgeom_size); args.cgeom[DT] = 1; args.cgeom[DX] = args.bgeom[DX]; args.cgeom[DY] = args.bgeom[DY]; args.cgeom[DZ] = args.bgeom[DZ]; } else { parse_dims(cg, &args.cgeom, &args.cgeom_size); } if (NDIMS != args.bgeom_size) { FATAL_ERR("Found %zu dimensions (expected %d).\n", args.bgeom_size, NDIMS); } if (NULL != args.cgeom) { if (NDIMS != args.cgeom_size) { FATAL_ERR("Found %zu dimensions (expected %d).\n", args.cgeom_size, NDIMS); } } DEBUG_MESSAGE("dgeom (%zu:%zu:%zu:%zu)\n", args.dgeom[DT], args.dgeom[DX], args.dgeom[DY], args.dgeom[DZ]); DEBUG_MESSAGE("bgeom (%zu:%zu:%zu:%zu)\n", args.bgeom[DT], args.bgeom[DX], args.bgeom[DY], args.bgeom[DZ]); if (NULL != args.cgeom) { DEBUG_MESSAGE("cgeom (%zu:%zu:%zu:%zu)\n", args.cgeom[DT], args.cgeom[DX], args.cgeom[DY], args.cgeom[DZ]); } DEBUG_MESSAGE("(nn %zu, ppn %zu)\n", args.procs.nn, args.procs.ppn); DEBUG_MESSAGE("test filename %s\n", args.testfn); if (args.dgeom[DX] % args.procs.nn != 0) { FATAL_ERR("x must be a multiple of number of nodes.\n"); } if (args.dgeom[DY] % args.procs.ppn != 0) { FATAL_ERR("y must be a multiple of number of processes.\n"); } if (NULL != args.cgeom) { if (args.dgeom[DT] % args.cgeom[DT] != 0) { FATAL_ERR("Time range must be a multiple of time slice (range=%zu; slice=%zu)\n", args.dgeom[DT], args.cgeom[DT]); } } int nranks = 0; MPI_Comm_size(MPI_COMM_WORLD, &nranks); if (nranks != args.procs.nn * args.procs.ppn){ FATAL_ERR("Bad environment: np != nn * ppn; np(size of MPI_COMM_WORLD)=%d, nodes(nn)=%zu, ppn(procs per node)=%zu\n", nranks, args.procs.nn, args.procs.ppn); } if ((args.read_test == false) & (args.write_test == false) & (args.verify == false)) { args.write_test = true; } benchmark_t wbm; benchmark_init(&wbm); int header_printed = 0; benchmark_t rbm; benchmark_init(&rbm); if (args.write_test || args.verify) { benchmark_setup(&wbm, args.procs, NDIMS, args.dgeom, args.bgeom, args.cgeom, args.testfn, IO_MODE_WRITE, args.par_access, args.is_unlimited, args.fill_value); if(rank == 0){ print_header(& wbm); header_printed = 1; } } if (args.write_test) { benchmark_run(&wbm, NULL); report_t report; report_init(&report); report_setup(&report, &wbm); report_print(&report, args.report_type); report_destroy(&report); } if (args.read_test) { int ret; benchmark_setup(&rbm, args.procs, NDIMS, args.dgeom, args.bgeom, args.cgeom, args.testfn, IO_MODE_READ, args.par_access, args.is_unlimited, 0); if(rank == 0 && ! header_printed){ print_header(& rbm); header_printed = 1; } ret = benchmark_run(&rbm, args.verify ? wbm.block : NULL ); report_t report; report_init(&report); report_setup(&report, &rbm); report_print(&report, args.report_type); report_destroy(&report); }else if (args.verify) { int ret; benchmark_setup(& rbm, args.procs, NDIMS, args.dgeom, args.bgeom, args.cgeom, args.testfn, IO_MODE_READ, args.par_access, args.is_unlimited, 0); if(rank == 0 && ! header_printed){ print_header(& rbm); header_printed = 1; } ret = benchmark_run(& rbm, wbm.block); if (args.verify){ if (ret) { printf("TEST PASSED [%u]\n", wbm.rank); } else { printf("TEST FAILED [%u]\n", wbm.rank); } } } MPI_Finalize(); benchmark_destroy(&wbm); benchmark_destroy(&rbm); free(args.dgeom); free(args.bgeom); free(args.cgeom); free(args.testfn); return 0; }
AUD_Int32s perf_dtw_mfcc() { char inputPath[256] = { 0, }; char keywordPath[256] = { 0, }; AUD_Double threshold, minThreshold, maxThreshold, stepThreshold; AUD_Bool isRecognized = AUD_FALSE; AUD_Int32s data; AUD_Error error = AUD_ERROR_NONE; setbuf( stdin, NULL ); AUDLOG( "pls give keyword wav stream's path:\n" ); keywordPath[0] = '\0'; data = scanf( "%s", keywordPath ); AUDLOG( "keyword path is: %s\n", keywordPath ); setbuf( stdin, NULL ); AUDLOG( "pls give test wav stream's path:\n" ); inputPath[0] = '\0'; data = scanf( "%s", inputPath ); AUDLOG( "test stream path is: %s\n", inputPath ); setbuf( stdin, NULL ); AUDLOG( "pls give min test threshold:\n" ); data = scanf( "%lf", &minThreshold ); AUDLOG( "min threshold is: %.2f\n", minThreshold ); setbuf( stdin, NULL ); AUDLOG( "pls give max test threshold:\n" ); data = scanf( "%lf", &maxThreshold ); AUDLOG( "max threshold is: %.2f\n", maxThreshold ); setbuf( stdin, NULL ); AUDLOG( "pls give test threshold step:\n" ); data = scanf( "%lf", &stepThreshold ); AUDLOG( "threshold step is: %.2f\n", stepThreshold ); AUDLOG( "\n\n" ); // file & directory operation, linux dependent entry *pEntry = NULL; dir *pDir = NULL; entry *pKeywordEntry = NULL; dir *pKeywordDir = NULL; AUD_Feature keywordFeature; AUD_Int32s keywordSampleNum = 0; AUD_Int32s keywordWinNum = 0; AUD_Int8s keywordFile[256] = { 0, }; AUD_Int8s keywordName[256] = { 0, }; AUD_Int32s keywordID = 0; AUD_DTWSession dtwSession; AUD_Double score = 0.; AUD_Int32s sampleNum; AUD_Int32s keywordBufLen = 0; AUD_Int16s *pKeywordBuf = NULL; AUD_Int32s bufLen = 0; AUD_Int16s *pBuf = NULL; AUD_Int32s frameStride = FRAME_STRIDE; AUD_Int32s j; AUD_Int32s ret; // init performance benchmark void *hBenchmark = NULL; char logName[256] = { 0, }; snprintf( logName, 256, "dtw-mfcc-%d-%d-%d-%d", WOV_DTW_TYPE, WOV_DISTANCE_METRIC, WOV_DTWTRANSITION_STYLE, WOV_DTWSCORING_METHOD ); ret = benchmark_init( &hBenchmark, (AUD_Int8s*)logName, keywords, sizeof(keywords) / sizeof(keywords[0]) ); AUD_ASSERT( ret == 0 ); for ( threshold = minThreshold; threshold < maxThreshold + stepThreshold; threshold += stepThreshold ) { ret = benchmark_newthreshold( hBenchmark, threshold ); AUD_ASSERT( ret == 0 ); AUDLOG( "***********************************************\n" ); AUDLOG( "keyword training start...\n" ); pKeywordDir = openDir( (const char*)keywordPath ); keywordID = 0; while ( ( pKeywordEntry = scanDir( pKeywordDir ) ) ) { // train keyword keywordBufLen = SAMPLE_RATE * BYTES_PER_SAMPLE * 10; pKeywordBuf = (AUD_Int16s*)calloc( keywordBufLen, 1 ); AUD_ASSERT( pKeywordBuf ); snprintf( (char*)keywordFile, 256, "%s/%s", (const char*)keywordPath, pKeywordEntry->name ); keywordSampleNum = readWavFromFile( keywordFile, pKeywordBuf, keywordBufLen ); if ( keywordSampleNum < 0 ) { continue; } // front end processing // pre-emphasis sig_preemphasis( pKeywordBuf, pKeywordBuf, keywordSampleNum ); for ( j = 0; j * frameStride + FRAME_LEN <= keywordSampleNum; j++ ) { ; } AUDLOG( "pattern[%d: %s] valid frame number[%d]\n", keywordID, keywordFile, j ); keywordWinNum = j; keywordFeature.featureMatrix.rows = keywordWinNum - MFCC_DELAY; keywordFeature.featureMatrix.cols = MFCC_FEATDIM; keywordFeature.featureMatrix.dataType = AUD_DATATYPE_INT32S; ret = createMatrix( &(keywordFeature.featureMatrix) ); AUD_ASSERT( ret == 0 ); keywordFeature.featureNorm.len = keywordWinNum - MFCC_DELAY; keywordFeature.featureNorm.dataType = AUD_DATATYPE_INT64S; ret = createVector( &(keywordFeature.featureNorm) ); AUD_ASSERT( ret == 0 ); void *hKeywordMfccHandle = NULL; // init mfcc handle error = mfcc16s32s_init( &hKeywordMfccHandle, FRAME_LEN, WINDOW_TYPE, MFCC_ORDER, frameStride, SAMPLE_RATE, COMPRESS_TYPE ); AUD_ASSERT( error == AUD_ERROR_NONE ); // calc MFCC feature error = mfcc16s32s_calc( hKeywordMfccHandle, pKeywordBuf, keywordSampleNum, &keywordFeature ); AUD_ASSERT( error == AUD_ERROR_NONE ); // deinit mfcc handle error = mfcc16s32s_deinit( &hKeywordMfccHandle ); AUD_ASSERT( error == AUD_ERROR_NONE ); strncpy( (char*)keywordName, pKeywordEntry->name, 255 ); ret = benchmark_newtemplate( hBenchmark, keywordName ); AUD_ASSERT( ret == 0 ); keywordID++; keywordBufLen = 0; free( pKeywordBuf ); pKeywordBuf = NULL; AUDLOG( "keyword training finish...\n" ); // recognize pEntry = NULL; pDir = NULL; pDir = openDir( (const char*)inputPath ); #if PERF_PROFILE AUD_Tick t; #endif while ( ( pEntry = scanDir( pDir ) ) ) { AUD_Int8s inputStream[256] = { 0, }; void *hMfccHandle = NULL; AUD_Summary fileSummary; snprintf( (char*)inputStream, 256, "%s/%s", (const char*)inputPath, pEntry->name ); ret = parseWavFromFile( inputStream, &fileSummary ); if ( ret < 0 ) { continue; } AUD_ASSERT( fileSummary.channelNum == CHANNEL_NUM && fileSummary.bytesPerSample == BYTES_PER_SAMPLE && fileSummary.sampleRate == SAMPLE_RATE ); AUDLOG( "input stream: %s\n", inputStream ); bufLen = fileSummary.dataChunkBytes; pBuf = (AUD_Int16s*)calloc( bufLen + 100, 1 ); AUD_ASSERT( pBuf ); #if PERF_PROFILE t = -time_gettick(); #endif sampleNum = readWavFromFile( inputStream, pBuf, bufLen ); AUD_ASSERT( sampleNum > 0 ); #if PERF_PROFILE t += time_gettick(); AUDLOG( "PERF: read wav files takes %.2f ms\n", t / 1000. ); #endif // front end processing // pre-emphasis #if PERF_PROFILE t = -time_gettick(); #endif sig_preemphasis( pBuf, pBuf, sampleNum ); #if PERF_PROFILE t += time_gettick(); AUDLOG( "PERF: pre-emphasis takes %.2f ms\n", t / 1000. ); #endif for ( j = 0; j * frameStride + FRAME_LEN <= sampleNum; j++ ) { ; } #if PERF_PROFILE t = -time_gettick(); #endif AUD_Feature inFeature; inFeature.featureMatrix.rows = j - MFCC_DELAY; inFeature.featureMatrix.cols = MFCC_FEATDIM; inFeature.featureMatrix.dataType = AUD_DATATYPE_INT32S; ret = createMatrix( &(inFeature.featureMatrix) ); AUD_ASSERT( ret == 0 ); #if PERF_PROFILE t += time_gettick(); AUDLOG( "PERF: create feature matrix takes %.2f ms\n", t / 1000. ); #endif #if PERF_PROFILE t = -time_gettick(); #endif inFeature.featureNorm.len = j - MFCC_DELAY; inFeature.featureNorm.dataType = AUD_DATATYPE_INT64S; ret = createVector( &(inFeature.featureNorm) ); AUD_ASSERT( ret == 0 ); #if PERF_PROFILE t += time_gettick(); AUDLOG( "PERF: create feature norm takes %.2f ms\n", t / 1000. ); #endif // init mfcc handle #if PERF_PROFILE t = -time_gettick(); #endif error = mfcc16s32s_init( &hMfccHandle, FRAME_LEN, WINDOW_TYPE, MFCC_ORDER, frameStride, SAMPLE_RATE, COMPRESS_TYPE ); AUD_ASSERT( error == AUD_ERROR_NONE ); #if PERF_PROFILE t += time_gettick(); AUDLOG( "PERF: mfcc init takes %.2f ms\n", t / 1000. ); #endif #if PERF_PROFILE t = -time_gettick(); #endif error = mfcc16s32s_calc( hMfccHandle, pBuf, sampleNum, &inFeature ); AUD_ASSERT( error == AUD_ERROR_NONE ); #if PERF_PROFILE t += time_gettick(); AUDLOG( "PERF: mfcc calc takes %.2f ms\n", t / 1000. ); #endif // init dtw match dtwSession.dtwType = WOV_DTW_TYPE; dtwSession.distType = WOV_DISTANCE_METRIC; dtwSession.transitionType = WOV_DTWTRANSITION_STYLE; error = dtw_initsession( &dtwSession, &keywordFeature, inFeature.featureMatrix.rows ); AUD_ASSERT( error == AUD_ERROR_NONE ); #if PERF_PROFILE t = -time_gettick(); #endif error = dtw_updatefrmcost( &dtwSession, &inFeature ); AUD_ASSERT( error == AUD_ERROR_NONE ); #if PERF_PROFILE t += time_gettick(); AUDLOG( "PERF: dtw update frame cost takes %.2f ms\n", t / 1000. ); #endif #if PERF_PROFILE t = -time_gettick(); #endif error = dtw_match( &dtwSession, WOV_DTWSCORING_METHOD, &score, NULL ); AUD_ASSERT( error == AUD_ERROR_NONE ); #if PERF_PROFILE t += time_gettick(); AUDLOG( "PERF: dtw match takes %.2f ms\n", t / 1000. ); #endif error = dtw_deinitsession( &dtwSession ); AUD_ASSERT( error == AUD_ERROR_NONE ); // deinit mfcc handle error = mfcc16s32s_deinit( &hMfccHandle ); AUD_ASSERT( error == AUD_ERROR_NONE ); ret = destroyMatrix( &(inFeature.featureMatrix) ); AUD_ASSERT( ret == 0 ); ret = destroyVector( &(inFeature.featureNorm) ); AUD_ASSERT( ret == 0 ); isRecognized = AUD_FALSE; if ( score <= threshold ) { isRecognized = AUD_TRUE; } AUDLOG( "score: %.2f\n", score ); // insert log entry ret = benchmark_additem( hBenchmark, (AUD_Int8s*)pEntry->name, score, isRecognized ); AUD_ASSERT( ret == 0 ); bufLen = 0; free( pBuf ); pBuf = NULL; } closeDir( pDir ); pDir = NULL; ret = benchmark_finalizetemplate( hBenchmark ); AUD_ASSERT( ret == 0 ); ret = destroyMatrix( &(keywordFeature.featureMatrix) ); AUD_ASSERT( ret == 0 ); ret = destroyVector( &(keywordFeature.featureNorm) ); AUD_ASSERT( ret == 0 ); } closeDir( pKeywordDir ); pKeywordDir = NULL; ret = benchmark_finalizethreshold( hBenchmark ); AUD_ASSERT( ret == 0 ); } ret = benchmark_free( &hBenchmark ); AUD_ASSERT( ret == 0 ); AUDLOG( "DTW-MFCC Benchmark finished\n" ); return 0; }
void epoll_benchmark_init (void) { benchmark_init(); }
int main(int argc, char *argv[]) { gearman_benchmark_st benchmark; int c; char *host= NULL; in_port_t port= 0; char *function= NULL; uint32_t count= 0; gearman_return_t ret; gearman_worker_st worker; benchmark_init(&benchmark); if (gearman_worker_create(&worker) == NULL) { fprintf(stderr, "Memory allocation failure on worker creation\n"); exit(1); } while ((c = getopt(argc, argv, "c:f:h:p:v")) != -1) { switch(c) { case 'c': count= (uint32_t)atoi(optarg); break; case 'f': function= optarg; ret= gearman_worker_add_function(&worker, function, 0, worker_fn, &benchmark); if (ret != GEARMAN_SUCCESS) { fprintf(stderr, "%s\n", gearman_worker_error(&worker)); exit(1); } break; case 'h': host= optarg; ret= gearman_worker_add_server(&worker, host, port); if (ret != GEARMAN_SUCCESS) { fprintf(stderr, "%s\n", gearman_worker_error(&worker)); exit(1); } break; case 'p': port= (in_port_t)atoi(optarg); break; case 'v': benchmark.verbose++; break; default: usage(argv[0]); exit(1); } } if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { fprintf(stderr, "signal:%d\n", errno); exit(1); } if (host == NULL) { ret= gearman_worker_add_server(&worker, NULL, port); if (ret != GEARMAN_SUCCESS) { fprintf(stderr, "%s\n", gearman_worker_error(&worker)); exit(1); } } if (function == NULL) { ret= gearman_worker_add_function(&worker, GEARMAN_BENCHMARK_DEFAULT_FUNCTION, 0, worker_fn, &benchmark); if (ret != GEARMAN_SUCCESS) { fprintf(stderr, "%s\n", gearman_worker_error(&worker)); exit(1); } } while (1) { ret= gearman_worker_work(&worker); if (ret != GEARMAN_SUCCESS) { fprintf(stderr, "%s\n", gearman_worker_error(&worker)); break; } if (count > 0) { count--; if (count == 0) break; } } gearman_worker_free(&worker); return 0; }