diff --git a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/haplotypecaller/HaplotypeCaller.java b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/haplotypecaller/HaplotypeCaller.java index 276103277..7844741df 100644 --- a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/haplotypecaller/HaplotypeCaller.java +++ b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/haplotypecaller/HaplotypeCaller.java @@ -1043,7 +1043,7 @@ public class HaplotypeCaller extends ActiveRegionWalker, In referenceConfidenceModel.close(); //TODO remove the need to call close here for debugging, the likelihood output stream should be managed //TODO (open & close) at the walker, not the engine. - likelihoodCalculationEngine.close(); + likelihoodCalculationEngine.close(); logger.info("Ran local assembly on " + result + " active regions"); } diff --git a/protected/java/src/org/broadinstitute/sting/utils/pairhmm/DebugJNILoglessPairHMM.java b/protected/java/src/org/broadinstitute/sting/utils/pairhmm/DebugJNILoglessPairHMM.java index 7e50f0c30..dc0ee23f7 100644 --- a/protected/java/src/org/broadinstitute/sting/utils/pairhmm/DebugJNILoglessPairHMM.java +++ b/protected/java/src/org/broadinstitute/sting/utils/pairhmm/DebugJNILoglessPairHMM.java @@ -75,8 +75,9 @@ import java.io.IOException; */ public class DebugJNILoglessPairHMM extends LoglessPairHMM { + private static final boolean dumpSandboxOnly = false; //simulates ifdef private static final boolean debug = false; //simulates ifdef - private static final boolean verify = debug || true; //simulates ifdef + private static final boolean verify = !dumpSandboxOnly && (debug || true); //simulates ifdef private static final boolean debug0_1 = false; //simulates ifdef private static final boolean debug1 = false; //simulates ifdef private static final boolean debug2 = false; @@ -134,9 +135,11 @@ public class DebugJNILoglessPairHMM extends LoglessPairHMM { public void initialize( final List haplotypes, final Map> perSampleReadList, final int readMaxLength, final int haplotypeMaxLength ) { if(verify) + { super.initialize(haplotypes, perSampleReadList, readMaxLength, haplotypeMaxLength); - jniPairHMM.initialize(haplotypes, perSampleReadList, readMaxLength, haplotypeMaxLength); - haplotypeToHaplotypeListIdxMap = jniPairHMM.getHaplotypeToHaplotypeListIdxMap(); + jniPairHMM.initialize(haplotypes, perSampleReadList, readMaxLength, haplotypeMaxLength); + haplotypeToHaplotypeListIdxMap = jniPairHMM.getHaplotypeToHaplotypeListIdxMap(); + } } /** @@ -145,7 +148,8 @@ public class DebugJNILoglessPairHMM extends LoglessPairHMM { @Override public void finalizeRegion() { - jniPairHMM.finalizeRegion(); + if(!dumpSandboxOnly) + jniPairHMM.finalizeRegion(); } /** @@ -204,46 +208,61 @@ public class DebugJNILoglessPairHMM extends LoglessPairHMM { ++idx; } } - jniPairHMM.computeLikelihoods(reads, alleleHaplotypeMap, GCPArrayMap); - double[] likelihoodArray = jniPairHMM.getLikelihoodArray(); - //to compare values - final PerReadAlleleLikelihoodMap likelihoodMap = super.computeLikelihoods(reads, alleleHaplotypeMap, GCPArrayMap); + double[] likelihoodArray = null; + PerReadAlleleLikelihoodMap likelihoodMap = null; if(verify) { - //re-order values in likelihoodArray - double[] tmpArray = new double[numHaplotypes]; - idx = 0; - int idxInsideHaplotypeList = 0; - int readIdx = 0; - for(GATKSAMRecord read : reads) + jniPairHMM.computeLikelihoods(reads, alleleHaplotypeMap, GCPArrayMap); + likelihoodArray = jniPairHMM.getLikelihoodArray(); + //to compare values + likelihoodMap = super.computeLikelihoods(reads, alleleHaplotypeMap, GCPArrayMap); + } + else + { + likelihoodMap = new PerReadAlleleLikelihoodMap(); + likelihoodArray = new double[numTestcases]; + for(int i=0;i currEntry : alleleHaplotypeMap.entrySet())//order is important - access in same order always + //re-order values in likelihoodArray + double[] tmpArray = new double[numHaplotypes]; + idx = 0; + int idxInsideHaplotypeList = 0; + int readIdx = 0; + for(GATKSAMRecord read : reads) { - idxInsideHaplotypeList = haplotypeToHaplotypeListIdxMap.get(currEntry.getValue()); - likelihoodArray[idx] = tmpArray[idxInsideHaplotypeList]; - ++idx; + for(int j=0;j currEntry : alleleHaplotypeMap.entrySet())//order is important - access in same order always + { + idxInsideHaplotypeList = haplotypeToHaplotypeListIdxMap.get(currEntry.getValue()); + likelihoodArray[idx] = tmpArray[idxInsideHaplotypeList]; + ++idx; + } + readIdx += numHaplotypes; } - readIdx += numHaplotypes; - } - //for floating point values, no exact equality - //check whether numbers are close in terms of abs_error or relative_error - //For very large values, relative_error is relevant - //For very small values, abs_error is relevant - boolean toDump = false; - for(int i=0;i 1e-5 && relative_error > 1e-5) + //for floating point values, no exact equality + //check whether numbers are close in terms of abs_error or relative_error + //For very large values, relative_error is relevant + //For very small values, abs_error is relevant + for(int i=0;i 1e-6 && relative_error > 1e-6) + { + toDump = true; + break; + } } } //if numbers are not close, then dump out the data that produced the inconsistency @@ -251,24 +270,40 @@ public class DebugJNILoglessPairHMM extends LoglessPairHMM { { idx = 0; System.out.println("Dump : Java numReads "+readListSize+" numHaplotypes "+numHaplotypes); + boolean firstLine = true; for(GATKSAMRecord read : reads) { byte [] overallGCP = GCPArrayMap.get(read); + byte[] tmpByteArray = new byte[read.getReadBases().length]; for (Map.Entry currEntry : alleleHaplotypeMap.entrySet()) //order is important - access in same order always { byte[] haplotypeBases = currEntry.getValue().getBases(); debugDump("debug_dump.txt",new String(haplotypeBases)+" ",true); debugDump("debug_dump.txt",new String(read.getReadBases())+" ",true); for(int k=0;k m_filename_to_fptr; std::set m_written_files_set; @@ -52,6 +55,8 @@ class LoadTimeInitializer double m_sum_square_stats[TOTAL_NUMBER_STATS]; uint64_t m_min_stats[TOTAL_NUMBER_STATS]; uint64_t m_max_stats[TOTAL_NUMBER_STATS]; + unsigned m_buffer_size; + uint64_t* m_buffer; }; extern LoadTimeInitializer g_load_time_initializer; diff --git a/public/c++/VectorPairHMM/Sandbox.cc b/public/c++/VectorPairHMM/Sandbox.cc index 7c10e0620..8fb0d0b67 100644 --- a/public/c++/VectorPairHMM/Sandbox.cc +++ b/public/c++/VectorPairHMM/Sandbox.cc @@ -73,7 +73,9 @@ JNIEXPORT void JNICALL Java_Sandbox_doEverythingNative (JNIEnv* env, jobject thisObject, jstring fileNameString) { const char* fileName = env->GetStringUTFChars(fileNameString, 0); - do_compute((char*)fileName); + char local_array[800]; + strncpy(local_array, fileName, 200); env->ReleaseStringUTFChars(fileNameString, fileName); + do_compute(local_array, true, 10000, false); } diff --git a/public/c++/VectorPairHMM/baseline.cc b/public/c++/VectorPairHMM/baseline.cc index 232df83f2..290a3a4a2 100644 --- a/public/c++/VectorPairHMM/baseline.cc +++ b/public/c++/VectorPairHMM/baseline.cc @@ -1,6 +1,8 @@ #include "headers.h" #include "template.h" #include "utils.h" +#include "LoadTimeInitializer.h" + using namespace std; template NUMBER compute_full_prob(testcase *tc, NUMBER *before_last_log) @@ -10,12 +12,28 @@ NUMBER compute_full_prob(testcase *tc, NUMBER *before_last_log) int COLS = tc->haplen + 1; Context ctx; - + //#define USE_STACK_ALLOCATION 1 +#ifdef USE_STACK_ALLOCATION + NUMBER M[ROWS][COLS]; + NUMBER X[ROWS][COLS]; + NUMBER Y[ROWS][COLS]; + NUMBER p[ROWS][6]; +#else //allocate on heap in way that simulates a 2D array. Having a 2D array instead of //a straightforward array of pointers ensures that all data lies 'close' in memory, increasing //the chance of being stored together in the cache. Also, prefetchers can learn memory access //patterns for 2D arrays, not possible for array of pointers + //bool locally_allocated = false; + //NUMBER* common_buffer = 0; NUMBER* common_buffer = new NUMBER[3*ROWS*COLS + ROWS*6]; + //unsigned curr_size = sizeof(NUMBER)*(3*ROWS*COLS + ROWS*6); + //if(true) + //{ + //common_buffer = new NUMBER[3*ROWS*COLS + ROWS*6]; + //locally_allocated = true; + //} + //else + //common_buffer = (NUMBER*)(g_load_time_initializer.get_buffer()); //pointers to within the allocated buffer NUMBER** common_pointer_buffer = new NUMBER*[4*ROWS]; NUMBER* ptr = common_buffer; @@ -25,14 +43,11 @@ NUMBER compute_full_prob(testcase *tc, NUMBER *before_last_log) for(;i<4*ROWS;++i, ptr+=6) common_pointer_buffer[i] = ptr; - //NUMBER M[ROWS][COLS]; - //NUMBER X[ROWS][COLS]; - //NUMBER Y[ROWS][COLS]; - //NUMBER p[ROWS][6]; NUMBER** M = common_pointer_buffer; NUMBER** X = M + ROWS; NUMBER** Y = X + ROWS; NUMBER** p = Y + ROWS; +#endif p[0][MM] = ctx._(0.0); @@ -111,8 +126,11 @@ NUMBER compute_full_prob(testcase *tc, NUMBER *before_last_log) if (before_last_log != NULL) *before_last_log = result; +#ifndef USE_STACK_ALLOCATION delete common_pointer_buffer; + //if(locally_allocated) delete common_buffer; +#endif return result; //return ctx.LOG10(result) - ctx.LOG10_INITIAL_CONSTANT; diff --git a/public/c++/VectorPairHMM/org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM.cc b/public/c++/VectorPairHMM/org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM.cc index 0f5219dd4..2d8dbaf3d 100644 --- a/public/c++/VectorPairHMM/org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM.cc +++ b/public/c++/VectorPairHMM/org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM.cc @@ -191,25 +191,32 @@ inline JNIEXPORT void JNICALL Java_org_broadinstitute_sting_utils_pairhmm_Vector } } +//#define DO_WARMUP +//#define DO_REPEAT_PROFILING //Do compute over vector of testcase structs inline void compute_testcases(vector& tc_array, unsigned numTestCases, double* likelihoodDoubleArray, unsigned maxNumThreadsToUse) { -#pragma omp parallel for schedule (dynamic,10000) num_threads(maxNumThreadsToUse) - for(unsigned tc_idx=0;tc_idxGetArrayLength(likelihoodArray) == numTestCases); #endif +#ifdef DO_WARMUP + vector >& haplotypeBasesArrayVector = g_haplotypeBasesArrayVector; + for(unsigned i=0;iGetArrayLength(haplotypeBasesArrayVector[i].first); + for(unsigned j=0;jGetArrayLength(readBasesArrayVector[i][j].first); + for(unsigned k=0;k