Contains profiling, exception tracking, PAPI code
Contains Sandbox Java
This commit is contained in:
parent
6d4d776633
commit
24f8aef344
|
|
@ -6,6 +6,7 @@ tests
|
|||
hmm_Mohammad
|
||||
pairhmm-template-main
|
||||
*.swp
|
||||
*.class
|
||||
checker
|
||||
reformat
|
||||
subdir_checkout.sh
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ void LoadTimeInitializer::debug_close()
|
|||
m_filename_to_fptr.clear();
|
||||
}
|
||||
|
||||
void LoadTimeInitializer::dump_sandbox(testcase& tc)
|
||||
void LoadTimeInitializer::dump_sandbox(testcase& tc, unsigned tc_idx, unsigned numReads, unsigned numHaplotypes)
|
||||
{
|
||||
unsigned haplotypeLength = tc.haplen;
|
||||
unsigned readLength = tc.rslen;
|
||||
|
|
@ -108,5 +108,7 @@ void LoadTimeInitializer::dump_sandbox(testcase& tc)
|
|||
dumpFptr<<" ";
|
||||
for(unsigned k=0;k<readLength;++k)
|
||||
dumpFptr<<(char)(tc.c[k]+33);
|
||||
if(tc_idx == 0) //new region
|
||||
dumpFptr << " "<< numReads << " "<<numHaplotypes;
|
||||
dumpFptr<<"\n";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class LoadTimeInitializer
|
|||
void debug_dump(std::string filename, std::string s, bool to_append, bool add_newline=true);
|
||||
void debug_close();
|
||||
|
||||
void dump_sandbox(testcase& tc);
|
||||
void dump_sandbox(testcase& tc, unsigned tc_idx, unsigned numReads, unsigned numHaplotypes);
|
||||
void open_sandbox() { m_sandbox_fptr.open("sandbox.txt", std::ios::app); }
|
||||
void close_sandbox() { m_sandbox_fptr.close(); }
|
||||
|
||||
|
|
@ -29,9 +29,9 @@ class LoadTimeInitializer
|
|||
double m_sumNumTestcases;
|
||||
double m_sumSquareNumTestcases;
|
||||
uint64_t m_sumNumDoubleTestcases;
|
||||
double m_sumReadLengths;
|
||||
double m_sumHaplotypeLengths;
|
||||
double m_sumProductReadLengthHaplotypeLength;
|
||||
uint64_t m_sumReadLengths;
|
||||
uint64_t m_sumHaplotypeLengths;
|
||||
uint64_t m_sumProductReadLengthHaplotypeLength;
|
||||
double m_sumSquareProductReadLengthHaplotypeLength;
|
||||
unsigned m_maxNumTestcases;
|
||||
unsigned m_num_invocations;
|
||||
|
|
@ -46,5 +46,7 @@ class LoadTimeInitializer
|
|||
};
|
||||
extern LoadTimeInitializer g_load_time_initializer;
|
||||
|
||||
#define SIZE_PER_TESTCASE 6*10000
|
||||
#define SIZE_PER_BUFFER 10000
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -13,6 +13,15 @@ CXX=icc
|
|||
|
||||
LDFLAGS=-lm -lrt $(OMPLDFLAGS)
|
||||
|
||||
#USE_PAPI=1
|
||||
PAPI_DIR=/home/karthikg/softwares/papi-5.3.0
|
||||
ifdef USE_PAPI
|
||||
ifeq ($(USE_PAPI),1)
|
||||
COMMON_COMPILATION_FLAGS+=-I$(PAPI_DIR)/include
|
||||
LDFLAGS+=-L$(PAPI_DIR)/lib -lpapi
|
||||
endif
|
||||
endif
|
||||
|
||||
BIN=libVectorLoglessPairHMM.so pairhmm-template-main checker
|
||||
#BIN=checker
|
||||
|
||||
|
|
@ -22,14 +31,14 @@ DF=$(DEPDIR)/$(*).d
|
|||
#Common across libJNI and sandbox
|
||||
COMMON_SOURCES=utils.cc avx_function_instantiations.cc baseline.cc sse_function_instantiations.cc LoadTimeInitializer.cc
|
||||
#Part of libJNI
|
||||
LIBSOURCES=org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM.cc org_broadinstitute_sting_utils_pairhmm_DebugJNILoglessPairHMM.cc $(COMMON_SOURCES)
|
||||
LIBSOURCES=org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM.cc org_broadinstitute_sting_utils_pairhmm_DebugJNILoglessPairHMM.cc Sandbox.cc $(COMMON_SOURCES)
|
||||
SOURCES=$(LIBSOURCES) pairhmm-template-main.cc pairhmm-1-base.cc
|
||||
LIBOBJECTS=$(LIBSOURCES:.cc=.o)
|
||||
COMMON_OBJECTS=$(COMMON_SOURCES:.cc=.o)
|
||||
|
||||
|
||||
#No vectorization for these files
|
||||
NO_VECTOR_SOURCES=org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM.cc org_broadinstitute_sting_utils_pairhmm_DebugJNILoglessPairHMM.cc pairhmm-template-main.cc pairhmm-1-base.cc utils.cc baseline.cc LoadTimeInitializer.cc
|
||||
NO_VECTOR_SOURCES=org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM.cc org_broadinstitute_sting_utils_pairhmm_DebugJNILoglessPairHMM.cc pairhmm-template-main.cc pairhmm-1-base.cc utils.cc baseline.cc LoadTimeInitializer.cc Sandbox.cc
|
||||
#Use -xAVX for these files
|
||||
AVX_SOURCES=avx_function_instantiations.cc
|
||||
#Use -xSSE4.2 for these files
|
||||
|
|
@ -43,7 +52,7 @@ $(AVX_OBJECTS): CXXFLAGS=$(COMMON_COMPILATION_FLAGS) -xAVX
|
|||
$(SSE_OBJECTS): CXXFLAGS=$(COMMON_COMPILATION_FLAGS) -xSSE4.2
|
||||
OBJECTS=$(NO_VECTOR_OBJECTS) $(AVX_OBJECTS) $(SSE_OBJECTS)
|
||||
|
||||
all: $(BIN)
|
||||
all: $(BIN) Sandbox.class
|
||||
|
||||
-include $(addprefix $(DEPDIR)/,$(SOURCES:.cc=.d))
|
||||
|
||||
|
|
@ -61,6 +70,8 @@ $(OBJECTS): %.o: %.cc
|
|||
@mkdir -p $(DEPDIR)
|
||||
$(CXX) -c -MMD -MF $(DF) $(CXXFLAGS) $(OUTPUT_OPTION) $<
|
||||
|
||||
Sandbox.class: Sandbox.java
|
||||
javac Sandbox.java
|
||||
|
||||
clean:
|
||||
rm -rf $(BIN) *.o $(DEPDIR)
|
||||
rm -rf $(BIN) *.o $(DEPDIR) *.class
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
#include "Sandbox.h"
|
||||
#include "org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM.h"
|
||||
#include "utils.h"
|
||||
#include "jni_common.h"
|
||||
/*
|
||||
* Class: Sandbox
|
||||
* Method: jniGetMachineType
|
||||
* Signature: ()J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_Sandbox_jniGetMachineType
|
||||
(JNIEnv * env, jobject thisObj)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: Sandbox
|
||||
* Method: jniInitializeClassFieldsAndMachineMask
|
||||
* Signature: (Ljava/lang/Class;Ljava/lang/Class;J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_Sandbox_jniInitializeClassFieldsAndMachineMask
|
||||
(JNIEnv* env, jobject thisObject, jclass readDataHolderClass, jclass haplotypeDataHolderClass, jlong mask)
|
||||
{
|
||||
Java_org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM_jniInitializeClassFieldsAndMachineMask(env, thisObject, readDataHolderClass,
|
||||
haplotypeDataHolderClass, mask);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: Sandbox
|
||||
* Method: jniInitializeHaplotypes
|
||||
* Signature: (I[LSandbox/JNIHaplotypeDataHolderClass;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_Sandbox_jniInitializeHaplotypes
|
||||
(JNIEnv * env, jobject thisObject, jint numHaplotypes, jobjectArray haplotypeDataArray)
|
||||
{
|
||||
Java_org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM_jniInitializeHaplotypes(env, thisObject, numHaplotypes, haplotypeDataArray);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: Sandbox
|
||||
* Method: jniFinalizeRegion
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_Sandbox_jniFinalizeRegion
|
||||
(JNIEnv * env, jobject thisObject)
|
||||
{
|
||||
Java_org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM_jniFinalizeRegion(env, thisObject);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: Sandbox
|
||||
* Method: jniComputeLikelihoods
|
||||
* Signature: (II[LSandbox/JNIReadDataHolderClass;[LSandbox/JNIHaplotypeDataHolderClass;[DI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_Sandbox_jniComputeLikelihoods
|
||||
(JNIEnv* env, jobject thisObject, jint numReads, jint numHaplotypes,
|
||||
jobjectArray readDataArray, jobjectArray haplotypeDataArray, jdoubleArray likelihoodArray, jint maxNumThreadsToUse)
|
||||
{
|
||||
Java_org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM_jniComputeLikelihoods(env, thisObject,
|
||||
numReads, numHaplotypes, readDataArray, haplotypeDataArray, likelihoodArray, maxNumThreadsToUse);
|
||||
}
|
||||
/*
|
||||
* Class: Sandbox
|
||||
* Method: jniClose
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_Sandbox_jniClose
|
||||
(JNIEnv* env, jobject thisObject)
|
||||
{ Java_org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM_jniClose(env, thisObject); }
|
||||
|
||||
JNIEXPORT void JNICALL Java_Sandbox_doEverythingNative
|
||||
(JNIEnv* env, jobject thisObject, jstring fileNameString)
|
||||
{
|
||||
const char* fileName = env->GetStringUTFChars(fileNameString, 0);
|
||||
do_compute((char*)fileName);
|
||||
env->ReleaseStringUTFChars(fileNameString, fileName);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class Sandbox */
|
||||
|
||||
#ifndef _Included_Sandbox
|
||||
#define _Included_Sandbox
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#undef Sandbox_enableAll
|
||||
#define Sandbox_enableAll -1LL
|
||||
/*
|
||||
* Class: Sandbox
|
||||
* Method: jniGetMachineType
|
||||
* Signature: ()J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_Sandbox_jniGetMachineType
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: Sandbox
|
||||
* Method: jniInitializeClassFieldsAndMachineMask
|
||||
* Signature: (Ljava/lang/Class;Ljava/lang/Class;J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_Sandbox_jniInitializeClassFieldsAndMachineMask
|
||||
(JNIEnv *, jobject, jclass, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: Sandbox
|
||||
* Method: jniInitializeHaplotypes
|
||||
* Signature: (I[LSandbox/JNIHaplotypeDataHolderClass;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_Sandbox_jniInitializeHaplotypes
|
||||
(JNIEnv *, jobject, jint, jobjectArray);
|
||||
|
||||
/*
|
||||
* Class: Sandbox
|
||||
* Method: jniFinalizeRegion
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_Sandbox_jniFinalizeRegion
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: Sandbox
|
||||
* Method: jniComputeLikelihoods
|
||||
* Signature: (II[LSandbox/JNIReadDataHolderClass;[LSandbox/JNIHaplotypeDataHolderClass;[DI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_Sandbox_jniComputeLikelihoods
|
||||
(JNIEnv *, jobject, jint, jint, jobjectArray, jobjectArray, jdoubleArray, jint);
|
||||
|
||||
/*
|
||||
* Class: Sandbox
|
||||
* Method: jniClose
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_Sandbox_jniClose
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: Sandbox
|
||||
* Method: doEverythingNative
|
||||
* Signature: ([B)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_Sandbox_doEverythingNative
|
||||
(JNIEnv *, jobject, jstring);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -0,0 +1,278 @@
|
|||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.io.File;
|
||||
import java.util.Scanner;
|
||||
import java.io.IOException;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class Sandbox {
|
||||
|
||||
private long setupTime = 0;
|
||||
private long computeTime = 0;
|
||||
//Used to copy references to byteArrays to JNI from reads
|
||||
protected class JNIReadDataHolderClass {
|
||||
public byte[] readBases = null;
|
||||
public byte[] readQuals = null;
|
||||
public byte[] insertionGOP = null;
|
||||
public byte[] deletionGOP = null;
|
||||
public byte[] overallGCP = null;
|
||||
}
|
||||
|
||||
//Used to copy references to byteArrays to JNI from haplotypes
|
||||
protected class JNIHaplotypeDataHolderClass {
|
||||
public byte[] haplotypeBases = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return 64-bit mask representing machine capabilities
|
||||
* Bit 0 is LSB, bit 63 MSB
|
||||
* Bit 0 represents sse4.2 availability
|
||||
* Bit 1 represents AVX availability
|
||||
*/
|
||||
public native long jniGetMachineType();
|
||||
public static final long enableAll = 0xFFFFFFFFFFFFFFFFl;
|
||||
|
||||
|
||||
/**
|
||||
* Function to initialize the fields of JNIReadDataHolderClass and JNIHaplotypeDataHolderClass from JVM.
|
||||
* C++ codegets FieldIDs for these classes once and re-uses these IDs for the remainder of the program. Field IDs do not
|
||||
* change per JVM session
|
||||
* @param readDataHolderClass class type of JNIReadDataHolderClass
|
||||
* @param haplotypeDataHolderClass class type of JNIHaplotypeDataHolderClass
|
||||
* @param mask mask is a 64 bit integer identical to the one received from jniGetMachineType(). Users can disable usage of some hardware features by zeroing some bits in the mask
|
||||
* */
|
||||
private native void jniInitializeClassFieldsAndMachineMask(Class<?> readDataHolderClass, Class<?> haplotypeDataHolderClass, long mask);
|
||||
|
||||
private static Boolean isVectorLoglessPairHMMLibraryLoaded = false;
|
||||
//The constructor is called only once inside PairHMMLikelihoodCalculationEngine
|
||||
public Sandbox() {
|
||||
synchronized(isVectorLoglessPairHMMLibraryLoaded) {
|
||||
//Load the library and initialize the FieldIDs
|
||||
if(!isVectorLoglessPairHMMLibraryLoaded) {
|
||||
System.loadLibrary("VectorLoglessPairHMM");
|
||||
isVectorLoglessPairHMMLibraryLoaded = true;
|
||||
jniInitializeClassFieldsAndMachineMask(JNIReadDataHolderClass.class, JNIHaplotypeDataHolderClass.class, enableAll); //need to do this only once
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private native void jniInitializeHaplotypes(final int numHaplotypes, JNIHaplotypeDataHolderClass[] haplotypeDataArray);
|
||||
|
||||
//Used to transfer data to JNI
|
||||
//Since the haplotypes are the same for all calls to computeLikelihoods within a region, transfer the haplotypes only once to the JNI per region
|
||||
public void initialize(final List<JNIHaplotypeDataHolderClass> haplotypes) {
|
||||
int numHaplotypes = haplotypes.size();
|
||||
JNIHaplotypeDataHolderClass[] haplotypeDataArray = new JNIHaplotypeDataHolderClass[numHaplotypes];
|
||||
int idx = 0;
|
||||
for(final JNIHaplotypeDataHolderClass currHaplotype : haplotypes)
|
||||
{
|
||||
haplotypeDataArray[idx] = new JNIHaplotypeDataHolderClass();
|
||||
haplotypeDataArray[idx].haplotypeBases = currHaplotype.haplotypeBases;
|
||||
++idx;
|
||||
}
|
||||
jniInitializeHaplotypes(numHaplotypes, haplotypeDataArray);
|
||||
}
|
||||
/**
|
||||
* Tell JNI to release arrays - really important if native code is directly accessing Java memory, if not
|
||||
* accessing Java memory directly, still important to release memory from C++
|
||||
*/
|
||||
private native void jniFinalizeRegion();
|
||||
|
||||
|
||||
public void finalizeRegion()
|
||||
{
|
||||
jniFinalizeRegion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Real compute kernel
|
||||
*/
|
||||
private native void jniComputeLikelihoods(int numReads, int numHaplotypes, JNIReadDataHolderClass[] readDataArray,
|
||||
JNIHaplotypeDataHolderClass[] haplotypeDataArray, double[] likelihoodArray, int maxNumThreadsToUse);
|
||||
|
||||
public void computeLikelihoods(final List<JNIReadDataHolderClass> reads, final List<JNIHaplotypeDataHolderClass> haplotypes) {
|
||||
//System.out.println("Region : "+reads.size()+" x "+haplotypes.size());
|
||||
long startTime = System.nanoTime();
|
||||
int readListSize = reads.size();
|
||||
int numHaplotypes = haplotypes.size();
|
||||
int numTestcases = readListSize*numHaplotypes;
|
||||
JNIReadDataHolderClass[] readDataArray = new JNIReadDataHolderClass[readListSize];
|
||||
int idx = 0;
|
||||
for(JNIReadDataHolderClass read : reads)
|
||||
{
|
||||
readDataArray[idx] = new JNIReadDataHolderClass();
|
||||
readDataArray[idx].readBases = read.readBases;
|
||||
readDataArray[idx].readQuals = read.readQuals;
|
||||
readDataArray[idx].insertionGOP = read.insertionGOP;
|
||||
readDataArray[idx].deletionGOP = read.deletionGOP;
|
||||
readDataArray[idx].overallGCP = read.overallGCP;
|
||||
++idx;
|
||||
}
|
||||
|
||||
double[] mLikelihoodArray = new double[readListSize*numHaplotypes]; //to store results
|
||||
setupTime += (System.nanoTime() - startTime);
|
||||
//for(reads)
|
||||
// for(haplotypes)
|
||||
// compute_full_prob()
|
||||
jniComputeLikelihoods(readListSize, numHaplotypes, readDataArray, null, mLikelihoodArray, 12);
|
||||
|
||||
computeTime += (System.nanoTime() - startTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print final profiling information from native code
|
||||
*/
|
||||
public native void jniClose();
|
||||
public void close()
|
||||
{
|
||||
System.out.println("Time spent in setup for JNI call : "+(setupTime*1e-9)+" compute time : "+(computeTime*1e-9));
|
||||
jniClose();
|
||||
}
|
||||
|
||||
public void parseSandboxFile(String filename)
|
||||
{
|
||||
File file = new File(filename);
|
||||
Scanner input = null;
|
||||
try
|
||||
{
|
||||
input = new Scanner(file);
|
||||
}
|
||||
catch(FileNotFoundException e)
|
||||
{
|
||||
System.err.println("File "+filename+" cannot be found/read");
|
||||
return;
|
||||
}
|
||||
int idx = 0;
|
||||
int numReads = 0;
|
||||
int numHaplotypes = 0;
|
||||
int readIdx = 0, testCaseIdx = 0, haplotypeIdx = 0;
|
||||
LinkedList<JNIHaplotypeDataHolderClass> haplotypeList = new LinkedList<JNIHaplotypeDataHolderClass>();
|
||||
LinkedList<JNIReadDataHolderClass> readList = new LinkedList<JNIReadDataHolderClass>();
|
||||
|
||||
byte[][] byteArray = new byte[6][];
|
||||
boolean firstLine = true;
|
||||
String[] currTokens = new String[8];
|
||||
while(input.hasNextLine())
|
||||
{
|
||||
String line = input.nextLine();
|
||||
Scanner lineScanner = new Scanner(line);
|
||||
idx = 0;
|
||||
while(lineScanner.hasNext())
|
||||
currTokens[idx++] = lineScanner.next();
|
||||
if(idx == 0)
|
||||
break;
|
||||
assert(idx >= 6);
|
||||
//start of new region
|
||||
if(idx == 8)
|
||||
{
|
||||
if(!firstLine)
|
||||
{
|
||||
initialize(haplotypeList);
|
||||
computeLikelihoods(readList, haplotypeList);
|
||||
finalizeRegion();
|
||||
}
|
||||
try
|
||||
{
|
||||
numReads = Integer.parseInt(currTokens[6]);
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
numReads = 1;
|
||||
}
|
||||
try
|
||||
{
|
||||
numHaplotypes = Integer.parseInt(currTokens[7]);
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
numHaplotypes = 1;
|
||||
}
|
||||
haplotypeIdx = readIdx = testCaseIdx = 0;
|
||||
readList.clear();
|
||||
haplotypeList.clear();
|
||||
}
|
||||
if(haplotypeIdx < numHaplotypes)
|
||||
{
|
||||
JNIHaplotypeDataHolderClass X = new JNIHaplotypeDataHolderClass();
|
||||
X.haplotypeBases = currTokens[0].getBytes();
|
||||
haplotypeList.add(X);
|
||||
}
|
||||
if(testCaseIdx%numHaplotypes == 0)
|
||||
{
|
||||
JNIReadDataHolderClass X = new JNIReadDataHolderClass();
|
||||
X.readBases = currTokens[1].getBytes();
|
||||
for(int i=2;i<6;++i)
|
||||
{
|
||||
byteArray[i] = currTokens[i].getBytes();
|
||||
for(int j=0;j<byteArray[i].length;++j)
|
||||
byteArray[i][j] -= 33; //normalize
|
||||
}
|
||||
X.readQuals = byteArray[2];
|
||||
X.insertionGOP = byteArray[3];
|
||||
X.deletionGOP = byteArray[4];
|
||||
X.overallGCP = byteArray[5];
|
||||
readList.add(X);
|
||||
}
|
||||
++testCaseIdx;
|
||||
++haplotypeIdx;
|
||||
|
||||
lineScanner.close();
|
||||
firstLine = false;
|
||||
}
|
||||
if(haplotypeList.size() > 0 && readList.size() > 0)
|
||||
{
|
||||
initialize(haplotypeList);
|
||||
computeLikelihoods(readList, haplotypeList);
|
||||
finalizeRegion();
|
||||
}
|
||||
|
||||
close();
|
||||
input.close();
|
||||
}
|
||||
|
||||
private native void doEverythingNative(String filename);
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
if(args.length <= 0)
|
||||
{
|
||||
System.err.println("Needs 1 argument - <filename>");
|
||||
System.exit(-1);
|
||||
}
|
||||
//// Get runtime
|
||||
//java.lang.Runtime rt = java.lang.Runtime.getRuntime();
|
||||
//// Start a new process: UNIX command ls
|
||||
//String cmd = "/home/karthikg/broad/gsa-unstable/public/c++/VectorPairHMM/checker "+args[0];
|
||||
//try
|
||||
//{
|
||||
//System.out.println(cmd);
|
||||
//java.lang.Process p = rt.exec(cmd);
|
||||
//try
|
||||
//{
|
||||
//p.waitFor();
|
||||
//java.io.InputStream is = p.getInputStream();
|
||||
//java.io.BufferedReader reader = new java.io.BufferedReader(new InputStreamReader(is));
|
||||
//// And print each line
|
||||
//String s = null;
|
||||
//while ((s = reader.readLine()) != null) {
|
||||
//System.out.println(s);
|
||||
//}
|
||||
//is.close();
|
||||
//}
|
||||
//catch(InterruptedException e)
|
||||
//{
|
||||
//System.err.println(e);
|
||||
//}
|
||||
//}
|
||||
//catch(IOException e)
|
||||
//{
|
||||
//System.err.println(e);
|
||||
//}
|
||||
Sandbox t = new Sandbox();
|
||||
t.doEverythingNative(args[0]);
|
||||
//t.parseSandboxFile(args[0]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class Sandbox_JNIHaplotypeDataHolderClass */
|
||||
|
||||
#ifndef _Included_Sandbox_JNIHaplotypeDataHolderClass
|
||||
#define _Included_Sandbox_JNIHaplotypeDataHolderClass
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class Sandbox_JNIReadDataHolderClass */
|
||||
|
||||
#ifndef _Included_Sandbox_JNIReadDataHolderClass
|
||||
#define _Included_Sandbox_JNIReadDataHolderClass
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -1,28 +1,28 @@
|
|||
#include "headers.h"
|
||||
#include "template.h"
|
||||
|
||||
extern uint64_t exceptions_array[128];
|
||||
template<class NUMBER>
|
||||
NUMBER compute_full_prob(testcase *tc, NUMBER *before_last_log = NULL)
|
||||
{
|
||||
int r, c;
|
||||
int ROWS = tc->rslen + 1;
|
||||
int COLS = tc->haplen + 1;
|
||||
int r, c;
|
||||
int ROWS = tc->rslen + 1;
|
||||
int COLS = tc->haplen + 1;
|
||||
|
||||
Context<NUMBER> ctx;
|
||||
Context<NUMBER> ctx;
|
||||
|
||||
NUMBER M[ROWS][COLS];
|
||||
NUMBER X[ROWS][COLS];
|
||||
NUMBER Y[ROWS][COLS];
|
||||
NUMBER p[ROWS][6];
|
||||
NUMBER M[ROWS][COLS];
|
||||
NUMBER X[ROWS][COLS];
|
||||
NUMBER Y[ROWS][COLS];
|
||||
NUMBER p[ROWS][6];
|
||||
|
||||
p[0][MM] = ctx._(0.0);
|
||||
p[0][GapM] = ctx._(0.0);
|
||||
p[0][MX] = ctx._(0.0);
|
||||
p[0][XX] = ctx._(0.0);
|
||||
p[0][MY] = ctx._(0.0);
|
||||
p[0][YY] = ctx._(0.0);
|
||||
for (r = 1; r < ROWS; r++)
|
||||
{
|
||||
p[0][MM] = ctx._(0.0);
|
||||
p[0][GapM] = ctx._(0.0);
|
||||
p[0][MX] = ctx._(0.0);
|
||||
p[0][XX] = ctx._(0.0);
|
||||
p[0][MY] = ctx._(0.0);
|
||||
p[0][YY] = ctx._(0.0);
|
||||
for (r = 1; r < ROWS; r++)
|
||||
{
|
||||
int _i = tc->i[r-1] & 127;
|
||||
int _d = tc->d[r-1] & 127;
|
||||
int _c = tc->c[r-1] & 127;
|
||||
|
|
@ -34,50 +34,62 @@ NUMBER compute_full_prob(testcase *tc, NUMBER *before_last_log = NULL)
|
|||
p[r][YY] = ctx.ph2pr[_c];
|
||||
//p[r][MY] = (r == ROWS - 1) ? ctx._(1.0) : ctx.ph2pr[_d];
|
||||
//p[r][YY] = (r == ROWS - 1) ? ctx._(1.0) : ctx.ph2pr[_c];
|
||||
}
|
||||
}
|
||||
|
||||
for (c = 0; c < COLS; c++)
|
||||
{
|
||||
for (c = 0; c < COLS; c++)
|
||||
{
|
||||
M[0][c] = ctx._(0.0);
|
||||
X[0][c] = ctx._(0.0);
|
||||
Y[0][c] = ctx.INITIAL_CONSTANT / (tc->haplen);
|
||||
}
|
||||
}
|
||||
|
||||
for (r = 1; r < ROWS; r++)
|
||||
{
|
||||
for (r = 1; r < ROWS; r++)
|
||||
{
|
||||
M[r][0] = ctx._(0.0);
|
||||
X[r][0] = X[r-1][0] * p[r][XX];
|
||||
Y[r][0] = ctx._(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
NUMBER result = ctx._(0.0);
|
||||
NUMBER result = ctx._(0.0);
|
||||
|
||||
for (r = 1; r < ROWS; r++)
|
||||
for (r = 1; r < ROWS; r++)
|
||||
for (c = 1; c < COLS; c++)
|
||||
{
|
||||
char _rs = tc->rs[r-1];
|
||||
char _hap = tc->hap[c-1];
|
||||
int _q = tc->q[r-1] & 127;
|
||||
NUMBER distm = ctx.ph2pr[_q];
|
||||
if (_rs == _hap || _rs == 'N' || _hap == 'N')
|
||||
fexcept_t flagp;
|
||||
char _rs = tc->rs[r-1];
|
||||
char _hap = tc->hap[c-1];
|
||||
int _q = tc->q[r-1] & 127;
|
||||
NUMBER distm = ctx.ph2pr[_q];
|
||||
if (_rs == _hap || _rs == 'N' || _hap == 'N')
|
||||
distm = ctx._(1.0) - distm;
|
||||
else
|
||||
distm = distm/3;
|
||||
M[r][c] = distm * (M[r-1][c-1] * p[r][MM] + X[r-1][c-1] * p[r][GapM] + Y[r-1][c-1] * p[r][GapM]);
|
||||
X[r][c] = M[r-1][c] * p[r][MX] + X[r-1][c] * p[r][XX];
|
||||
Y[r][c] = M[r][c-1] * p[r][MY] + Y[r][c-1] * p[r][YY];
|
||||
else
|
||||
distm = distm/3;
|
||||
|
||||
|
||||
//feclearexcept(FE_ALL_EXCEPT);
|
||||
M[r][c] = distm * (M[r-1][c-1] * p[r][MM] + X[r-1][c-1] * p[r][GapM] + Y[r-1][c-1] * p[r][GapM]);
|
||||
//M[r][c] = (M[r-1][c-1] * p[r][MM] + X[r-1][c-1] * p[r][GapM] + Y[r-1][c-1] * p[r][GapM]);
|
||||
//STORE_FP_EXCEPTIONS(flagp, exceptions_array);
|
||||
|
||||
//feclearexcept(FE_ALL_EXCEPT);
|
||||
X[r][c] = M[r-1][c] * p[r][MX] + X[r-1][c] * p[r][XX];
|
||||
//STORE_FP_EXCEPTIONS(flagp, exceptions_array);
|
||||
|
||||
//feclearexcept(FE_ALL_EXCEPT);
|
||||
Y[r][c] = M[r][c-1] * p[r][MY] + Y[r][c-1] * p[r][YY];
|
||||
//STORE_FP_EXCEPTIONS(flagp, exceptions_array);
|
||||
}
|
||||
|
||||
for (c = 0; c < COLS; c++)
|
||||
{
|
||||
for (c = 0; c < COLS; c++)
|
||||
{
|
||||
result += M[ROWS-1][c] + X[ROWS-1][c];
|
||||
}
|
||||
}
|
||||
|
||||
if (before_last_log != NULL)
|
||||
if (before_last_log != NULL)
|
||||
*before_last_log = result;
|
||||
|
||||
return result;
|
||||
//return ctx.LOG10(result) - ctx.LOG10_INITIAL_CONSTANT;
|
||||
return result;
|
||||
//return ctx.LOG10(result) - ctx.LOG10_INITIAL_CONSTANT;
|
||||
}
|
||||
|
||||
template double compute_full_prob<double>(testcase* tc, double* nextbuf);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
#ifndef COMMON_HEADERS_H
|
||||
#define COMMON_HEADERS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -22,4 +25,16 @@
|
|||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <fenv.h>
|
||||
|
||||
#define STORE_FP_EXCEPTIONS(flagp, exceptions_array) \
|
||||
fegetexceptflag(&flagp, FE_OVERFLOW | FE_UNDERFLOW | FE_DIVBYZERO | FE_INVALID | __FE_DENORM); \
|
||||
exceptions_array[FE_INVALID] += ((flagp & FE_INVALID)); \
|
||||
exceptions_array[__FE_DENORM] += ((flagp & __FE_DENORM) >> 1); \
|
||||
exceptions_array[FE_DIVBYZERO] += ((flagp & FE_DIVBYZERO) >> 2); \
|
||||
exceptions_array[FE_OVERFLOW] += ((flagp & FE_OVERFLOW) >> 3); \
|
||||
exceptions_array[FE_UNDERFLOW] += ((flagp & FE_UNDERFLOW) >> 4); \
|
||||
feclearexcept(FE_ALL_EXCEPT);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
#define JNI_COMMON_H
|
||||
|
||||
#include <jni.h>
|
||||
#define ENABLE_ASSERTIONS 1
|
||||
/*#define ENABLE_ASSERTIONS 1*/
|
||||
#define DO_PROFILING 1
|
||||
//#define DEBUG 1
|
||||
/*#define DEBUG 1*/
|
||||
//#define DEBUG0_1 1
|
||||
//#define DEBUG3 1
|
||||
/*#define DUMP_TO_SANDBOX 1*/
|
||||
|
|
|
|||
|
|
@ -5,16 +5,6 @@
|
|||
#include "utils.h"
|
||||
#include "LoadTimeInitializer.h"
|
||||
|
||||
char* all_ptrs[] = {
|
||||
"TCAAACCGAAATAAAGGCCAGTATATCCATATCCTTCCCATAAATGTTGATGGAAGAATTATTTGGAAGCCATATAGAATGAAATGACTCTATACACAAATTAAAACACAAAAACGTACTCAAAATAGTCCAGAGACTACAACTTCAAATGCAAAACTATAAATAATCTAAAAGAAAACCTAAGAGACATTC",
|
||||
"GTCCAGAGACTACAACTTCAAATGCAAAACTATAAATAATCTAACAGAAAACCTAAGAGACATTC",
|
||||
">D?@BAEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE@EEEEEEEEEEDEEEEEE?",
|
||||
"IIIIIIIIIIIIIIIIIIIIIIIIHHHHIIIIIIIIIIIIIIIIIIHHHHIIIIIIIIIIIIIIN",
|
||||
"IIIIIIIIIIIIIIIIIIIIIIIIHHHHIIIIIIIIIIIIIIIIIIHHHHIIIIIIIIIIIIIIN",
|
||||
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
|
||||
};
|
||||
char all_arrays[6][16384];
|
||||
|
||||
using namespace std;
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_broadinstitute_sting_utils_pairhmm_VectorLoglessPairHMM_jniGetMachineType
|
||||
|
|
@ -56,17 +46,6 @@ JNIEXPORT void JNICALL Java_org_broadinstitute_sting_utils_pairhmm_VectorLogless
|
|||
initialize_function_pointers((uint64_t)mask);
|
||||
cout.flush();
|
||||
}
|
||||
#if 0
|
||||
for(unsigned i=0;i<6;++i)
|
||||
{
|
||||
unsigned length = strlen(all_ptrs[i]);
|
||||
for(unsigned j=0;j<16384;++j)
|
||||
all_arrays[i][j] = all_ptrs[i][j%length];
|
||||
}
|
||||
for(unsigned i=2;i<6;++i)
|
||||
for(unsigned j=0;j<16384;++j)
|
||||
all_arrays[i][j] = all_arrays[i][j]-33;
|
||||
#endif
|
||||
}
|
||||
|
||||
//Since the list of haplotypes against which the reads are evaluated in PairHMM is the same for a region,
|
||||
|
|
@ -211,44 +190,18 @@ JNIEXPORT void JNICALL Java_org_broadinstitute_sting_utils_pairhmm_VectorLogless
|
|||
jbyte* haplotypeBasesArray = haplotypeBasesArrayVector[j].second;
|
||||
tc_array[tc_idx].rslen = (int)readLength;
|
||||
tc_array[tc_idx].haplen = (int)haplotypeLength;
|
||||
#if 0
|
||||
tc_array[tc_idx].hap = (char*)haplotypeBasesArray;
|
||||
tc_array[tc_idx].rs = (char*)readBasesArray;
|
||||
tc_array[tc_idx].q = (char*)readQualsArray;
|
||||
tc_array[tc_idx].i = (char*)insertionGOPArray;
|
||||
tc_array[tc_idx].d = (char*)deletionGOPArray;
|
||||
tc_array[tc_idx].c = (char*)overallGCPArray;
|
||||
#endif
|
||||
//#define MEMCPY_HACK
|
||||
#ifdef MEMCPY_HACK
|
||||
tc_array[tc_idx].hap = new char[haplotypeLength];
|
||||
tc_array[tc_idx].rs = new char[readLength];
|
||||
tc_array[tc_idx].q = new char[readLength];
|
||||
tc_array[tc_idx].i = new char[readLength];
|
||||
tc_array[tc_idx].d = new char[readLength];
|
||||
tc_array[tc_idx].c = new char[readLength];
|
||||
memcpy(tc_array[tc_idx].hap, haplotypeBasesArray, haplotypeLength);
|
||||
memcpy(tc_array[tc_idx].rs, readBasesArray, readLength);
|
||||
memcpy(tc_array[tc_idx].q, readQualsArray, readLength);
|
||||
memcpy(tc_array[tc_idx].i, insertionGOPArray, readLength);
|
||||
memcpy(tc_array[tc_idx].d, deletionGOPArray, readLength);
|
||||
memcpy(tc_array[tc_idx].c, overallGCPArray, readLength);
|
||||
#endif
|
||||
#if 0
|
||||
tc_array[tc_idx].hap = (char*)all_arrays[0];
|
||||
tc_array[tc_idx].rs = (char*)all_arrays[1];
|
||||
tc_array[tc_idx].q = (char*)all_arrays[2];
|
||||
tc_array[tc_idx].i = (char*)all_arrays[3];
|
||||
tc_array[tc_idx].d = (char*)all_arrays[4];
|
||||
tc_array[tc_idx].c = (char*)all_arrays[5];
|
||||
#endif
|
||||
|
||||
#ifdef DUMP_TO_SANDBOX
|
||||
g_load_time_initializer.dump_sandbox(tc_array[tc_idx]);
|
||||
#endif
|
||||
#ifdef DO_PROFILING
|
||||
g_load_time_initializer.m_sumProductReadLengthHaplotypeLength += (readLength*haplotypeLength);
|
||||
g_load_time_initializer.m_sumSquareProductReadLengthHaplotypeLength += ((readLength*haplotypeLength)*(readLength*haplotypeLength));
|
||||
#endif
|
||||
#ifdef DUMP_TO_SANDBOX
|
||||
g_load_time_initializer.dump_sandbox(tc_array[tc_idx], tc_idx, numReads, numHaplotypes);
|
||||
#endif
|
||||
++tc_idx;
|
||||
}
|
||||
|
|
@ -265,9 +218,7 @@ JNIEXPORT void JNICALL Java_org_broadinstitute_sting_utils_pairhmm_VectorLogless
|
|||
g_load_time_initializer.m_sumReadLengths += readLength;
|
||||
#endif
|
||||
}
|
||||
#ifdef DUMP_TO_SANDBOX
|
||||
g_load_time_initializer.close_sandbox();
|
||||
#endif
|
||||
|
||||
#ifdef DO_PROFILING
|
||||
g_load_time_initializer.m_data_transfer_time += get_time();
|
||||
#endif
|
||||
|
|
@ -296,16 +247,6 @@ JNIEXPORT void JNICALL Java_org_broadinstitute_sting_utils_pairhmm_VectorLogless
|
|||
}
|
||||
else
|
||||
result = (double)(log10f(result_avxf) - log10f(ldexpf(1.f, 120.f)));
|
||||
#if 0
|
||||
double result = 0;
|
||||
testcase& tc = tc_array[tc_idx];
|
||||
for(unsigned k=0;k<tc.rslen;++k)
|
||||
result += tc.rs[k] + tc.q[k] + tc.i[k] + tc.d[k] + tc.c[k];
|
||||
result /= tc.rslen;
|
||||
for(unsigned k=0;k<tc.haplen;++k)
|
||||
result += tc.hap[k];
|
||||
result = -fabs(result) - 1;
|
||||
#endif
|
||||
likelihoodDoubleArray[tc_idx] = result;
|
||||
}
|
||||
#ifdef DO_PROFILING
|
||||
|
|
@ -322,18 +263,6 @@ JNIEXPORT void JNICALL Java_org_broadinstitute_sting_utils_pairhmm_VectorLogless
|
|||
#endif
|
||||
RELEASE_DOUBLE_ARRAY_ELEMENTS(likelihoodArray, likelihoodDoubleArray, 0); //release mode 0, copy back results to Java memory
|
||||
|
||||
#ifdef MEMCPY_HACK
|
||||
for(tc_idx=0;tc_idx<numTestCases;++tc_idx)
|
||||
{
|
||||
delete tc_array[tc_idx].hap;
|
||||
delete tc_array[tc_idx].rs;
|
||||
delete tc_array[tc_idx].q;
|
||||
delete tc_array[tc_idx].i;
|
||||
delete tc_array[tc_idx].d;
|
||||
delete tc_array[tc_idx].c;
|
||||
}
|
||||
#endif
|
||||
|
||||
//Release read arrays first
|
||||
for(int i=readBasesArrayVector.size()-1;i>=0;--i)//note the order - reverse of GET
|
||||
{
|
||||
|
|
@ -360,6 +289,9 @@ JNIEXPORT void JNICALL Java_org_broadinstitute_sting_utils_pairhmm_VectorLogless
|
|||
#ifdef DEBUG
|
||||
g_load_time_initializer.debug_close();
|
||||
#endif
|
||||
#ifdef DUMP_TO_SANDBOX
|
||||
g_load_time_initializer.close_sandbox();
|
||||
#endif
|
||||
}
|
||||
|
||||
//Release haplotypes at the end of a region
|
||||
|
|
|
|||
|
|
@ -2,16 +2,11 @@
|
|||
//#define DEBUG0_1 1
|
||||
//#define DEBUG3 1
|
||||
#include "headers.h"
|
||||
#include "template.h"
|
||||
#include "utils.h"
|
||||
#include "LoadTimeInitializer.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define RUN_HYBRID
|
||||
|
||||
vector<double> results_vec;
|
||||
vector<testcase> tc_vector;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
#define BATCH_SIZE 5
|
||||
|
|
@ -20,6 +15,8 @@ int main(int argc, char** argv)
|
|||
cerr << "Needs path to input file as argument\n";
|
||||
exit(0);
|
||||
}
|
||||
do_compute(argv[1]);
|
||||
#if 0
|
||||
bool use_old_read_testcase = false;
|
||||
if(argc >= 3 && string(argv[2]) == "1")
|
||||
use_old_read_testcase = true;
|
||||
|
|
@ -39,7 +36,8 @@ int main(int argc, char** argv)
|
|||
ifptr.open(argv[1]);
|
||||
assert(ifptr.is_open());
|
||||
}
|
||||
|
||||
vector<double> results_vec;
|
||||
vector<testcase> tc_vector;
|
||||
tc_vector.clear();
|
||||
tc_vector.resize(BATCH_SIZE+4);
|
||||
results_vec.clear();
|
||||
|
|
@ -58,6 +56,7 @@ int main(int argc, char** argv)
|
|||
testcase tc_in;
|
||||
int break_value = 0;
|
||||
tc_vector.clear();
|
||||
g_load_time_initializer.open_sandbox();
|
||||
while(1)
|
||||
{
|
||||
break_value = use_old_read_testcase ? read_testcase(&tc_in, fptr) :
|
||||
|
|
@ -137,7 +136,7 @@ int main(int argc, char** argv)
|
|||
tc_vector.clear();
|
||||
if(all_ok)
|
||||
cout << "All outputs acceptable\n";
|
||||
cout << "Total vector time "<< ((double)total_time)/1e9 << " baseline time "<<baseline_time*1e-9<<"\n";
|
||||
cout << "Total vector time "<< (total_time*1e-9) << " baseline time "<<baseline_time*1e-9<<"\n";
|
||||
cout << "Product "<<product<<"\n";
|
||||
cout.flush();
|
||||
fflush(stdout);
|
||||
|
|
@ -145,6 +144,8 @@ int main(int argc, char** argv)
|
|||
fclose(fptr);
|
||||
else
|
||||
ifptr.close();
|
||||
g_load_time_initializer.close_sandbox();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,8 +102,8 @@ int read_testcase(testcase *tc, FILE* ifp)
|
|||
assert(strlen(d) == tc->rslen);
|
||||
assert(strlen(c) == tc->rslen);
|
||||
//assert(tc->rslen < MROWS);
|
||||
tc->ihap = (int *) malloc(tc->haplen*sizeof(int));
|
||||
tc->irs = (int *) malloc(tc->rslen*sizeof(int));
|
||||
//tc->ihap = (int *) malloc(tc->haplen*sizeof(int));
|
||||
//tc->irs = (int *) malloc(tc->rslen*sizeof(int));
|
||||
|
||||
tc->q = (char *) malloc(sizeof(char) * tc->rslen);
|
||||
tc->i = (char *) malloc(sizeof(char) * tc->rslen);
|
||||
|
|
@ -121,10 +121,10 @@ int read_testcase(testcase *tc, FILE* ifp)
|
|||
tc->i[x] = _i;
|
||||
tc->d[x] = _d;
|
||||
tc->c[x] = _c;
|
||||
tc->irs[x] = tc->rs[x];
|
||||
//tc->irs[x] = tc->rs[x];
|
||||
}
|
||||
for (x = 0; x < tc->haplen; x++)
|
||||
tc->ihap[x] = tc->hap[x];
|
||||
//for (x = 0; x < tc->haplen; x++)
|
||||
//tc->ihap[x] = tc->hap[x];
|
||||
|
||||
|
||||
free(q);
|
||||
|
|
@ -286,4 +286,182 @@ uint64_t diff_time(struct timespec& prev_time)
|
|||
return (uint64_t)((curr_time.tv_sec-prev_time.tv_sec)*1000000000+(curr_time.tv_nsec-prev_time.tv_nsec));
|
||||
}
|
||||
|
||||
//#define USE_PAPI
|
||||
#ifdef USE_PAPI
|
||||
#include "papi.h"
|
||||
#define NUM_PAPI_COUNTERS 4
|
||||
#endif
|
||||
|
||||
uint64_t exceptions_array[128];
|
||||
void do_compute(char* filename)
|
||||
{
|
||||
memset(exceptions_array, 0, 128*sizeof(uint64_t));
|
||||
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
|
||||
//assert(feenableexcept(FE_DIVBYZERO | FE_INVALID) >= 0);
|
||||
#ifdef USE_PAPI
|
||||
PAPI_num_counters();
|
||||
//int events[NUM_PAPI_COUNTERS] = { PAPI_TOT_INS, PAPI_TOT_CYC, PAPI_L1_DCM, PAPI_L1_ICM, PAPI_L3_TCM, PAPI_TLB_DM, PAPI_TLB_IM };
|
||||
//char* eventnames[NUM_PAPI_COUNTERS]= { "instructions", "cycles", "l1d_misses", "l1i_misses", "l3_misses", "dtlb_misses", "itlb_misses" };
|
||||
//long long values[NUM_PAPI_COUNTERS] = { 0, 0, 0, 0, 0, 0, 0 };
|
||||
//long long accum_values[NUM_PAPI_COUNTERS] = { 0, 0, 0, 0, 0, 0, 0 };
|
||||
//int events[NUM_PAPI_COUNTERS] = { PAPI_TOT_INS, PAPI_TOT_CYC, PAPI_L1_ICM };
|
||||
//char* eventnames[NUM_PAPI_COUNTERS]= { "instructions", "cycles", "l1i_misses"};
|
||||
//assert(PAPI_event_name_to_code("PERF_COUNT_HW_STALLED_CYCLES_FRONTEND",&(events[2])) == PAPI_OK);
|
||||
int events[NUM_PAPI_COUNTERS] = { 0, 0, 0, 0 };
|
||||
//assert(PAPI_event_name_to_code("ICACHE:IFETCH_STALL",&(events[2])) == PAPI_OK);
|
||||
//assert(PAPI_event_name_to_code("MACHINE_CLEARS:e",&(events[3])) == PAPI_OK);
|
||||
char* eventnames[NUM_PAPI_COUNTERS]= { "instructions", "cycles", "ifetch_stall", "store_misses" };
|
||||
assert(PAPI_event_name_to_code("ix86arch::INSTRUCTION_RETIRED",&(events[0])) == PAPI_OK);
|
||||
assert(PAPI_event_name_to_code("UNHALTED_REFERENCE_CYCLES",&(events[1])) == PAPI_OK);
|
||||
assert(PAPI_event_name_to_code("ICACHE:IFETCH_STALL", &(events[2])) == PAPI_OK);
|
||||
assert(PAPI_event_name_to_code("perf::L1-DCACHE-STORE-MISSES", &(events[3])) == PAPI_OK);
|
||||
long long values[NUM_PAPI_COUNTERS] = { 0, 0, 0, 0 };
|
||||
long long accum_values[NUM_PAPI_COUNTERS] = { 0, 0, 0, 0 };
|
||||
|
||||
#endif
|
||||
#define BATCH_SIZE 100000
|
||||
bool use_old_read_testcase = true;
|
||||
unsigned chunk_size = 100;
|
||||
std::ifstream ifptr;
|
||||
FILE* fptr = 0;
|
||||
if(use_old_read_testcase)
|
||||
{
|
||||
fptr = fopen(filename,"r");
|
||||
if(fptr == 0)
|
||||
cerr << "Could not open file "<<filename<<"\n";
|
||||
assert(fptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
ifptr.open(filename);
|
||||
assert(ifptr.is_open());
|
||||
}
|
||||
vector<testcase> tc_vector;
|
||||
tc_vector.clear();
|
||||
vector<double> results_vec;
|
||||
results_vec.clear();
|
||||
vector<double> baseline_results;
|
||||
baseline_results.clear();
|
||||
|
||||
bool all_ok = true;
|
||||
uint64_t total_time = 0;
|
||||
uint64_t baseline_time = 0;
|
||||
unsigned total_count = 0;
|
||||
unsigned num_testcases = 0;
|
||||
//unsigned curr_batch_size = rand()%BATCH_SIZE + 4; //min batch size
|
||||
unsigned curr_batch_size = BATCH_SIZE;
|
||||
|
||||
testcase tc_in;
|
||||
int break_value = 0;
|
||||
while(1)
|
||||
{
|
||||
break_value = use_old_read_testcase ? read_testcase(&tc_in, fptr) :
|
||||
read_mod_testcase(ifptr, &tc_in, true);
|
||||
tc_vector.push_back(tc_in);
|
||||
if(break_value >= 0)
|
||||
++num_testcases;
|
||||
if(num_testcases == curr_batch_size || (break_value < 0 && num_testcases > 0))
|
||||
{
|
||||
results_vec.resize(tc_vector.size());
|
||||
baseline_results.resize(tc_vector.size());
|
||||
|
||||
get_time();
|
||||
#ifdef USE_PAPI
|
||||
assert(PAPI_start_counters(events, NUM_PAPI_COUNTERS) == PAPI_OK);
|
||||
#endif
|
||||
#pragma omp parallel for schedule(dynamic,chunk_size) num_threads(12)
|
||||
for(unsigned i=0;i<num_testcases;++i)
|
||||
{
|
||||
double result = 0;
|
||||
float result_avxf = g_compute_full_prob_float(&(tc_vector[i]), 0);
|
||||
if (result_avxf < MIN_ACCEPTED) {
|
||||
double result_avxd = g_compute_full_prob_double(&(tc_vector[i]), 0);
|
||||
result = log10(result_avxd) - log10(ldexp(1.0, 1020.0));
|
||||
}
|
||||
else
|
||||
result = (double)(log10f(result_avxf) - log10f(ldexpf(1.f, 120.f)));
|
||||
results_vec[i] = result;
|
||||
}
|
||||
#ifdef USE_PAPI
|
||||
//assert(PAPI_accum_counters(values, NUM_PAPI_COUNTERS) == PAPI_OK);
|
||||
assert(PAPI_stop_counters(values, NUM_PAPI_COUNTERS) == PAPI_OK);
|
||||
#endif
|
||||
total_time += get_time();
|
||||
#ifdef USE_PAPI
|
||||
for(unsigned k=0;k<NUM_PAPI_COUNTERS;++k)
|
||||
accum_values[k] += values[k];
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#pragma omp parallel for schedule(dynamic,chunk_size)
|
||||
for(unsigned i=0;i<num_testcases;++i)
|
||||
{
|
||||
testcase& tc = tc_vector[i];
|
||||
float result_avxf = compute_full_prob<float>(&tc);
|
||||
double result = 0;
|
||||
if (result_avxf < MIN_ACCEPTED) {
|
||||
double result_avxd = compute_full_prob<double>(&tc);
|
||||
result = log10(result_avxd) - log10(ldexp(1.0, 1020.0));
|
||||
}
|
||||
else
|
||||
result = (double)(log10f(result_avxf) - log10f(ldexpf(1.f, 120.f)));
|
||||
baseline_results[i] = result;
|
||||
}
|
||||
baseline_time += get_time();
|
||||
for(unsigned i=0;i<num_testcases;++i)
|
||||
{
|
||||
double baseline_result = baseline_results[i];
|
||||
double abs_error = fabs(baseline_result-results_vec[i]);
|
||||
double rel_error = (baseline_result != 0) ? fabs(abs_error/baseline_result) : 0;
|
||||
if(abs_error > 1e-5 && rel_error > 1e-5)
|
||||
{
|
||||
cout << "Line "<<total_count+i<< " " << std::scientific << baseline_result << " "<<results_vec[i]<<"\n";
|
||||
all_ok = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for(unsigned i=0;i<num_testcases;++i)
|
||||
{
|
||||
delete tc_vector[i].rs;
|
||||
delete tc_vector[i].hap;
|
||||
delete tc_vector[i].q;
|
||||
delete tc_vector[i].i;
|
||||
delete tc_vector[i].d;
|
||||
delete tc_vector[i].c;
|
||||
}
|
||||
total_count += num_testcases;
|
||||
num_testcases = 0;
|
||||
tc_vector.clear();
|
||||
baseline_results.clear();
|
||||
results_vec.clear();
|
||||
//curr_batch_size = rand()%BATCH_SIZE + 4; //min batch size
|
||||
curr_batch_size = BATCH_SIZE;
|
||||
if(break_value < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
baseline_results.clear();
|
||||
results_vec.clear();
|
||||
tc_vector.clear();
|
||||
if(all_ok)
|
||||
cout << "All outputs acceptable\n";
|
||||
#ifdef USE_PAPI
|
||||
for(unsigned i=0;i<NUM_PAPI_COUNTERS;++i)
|
||||
cout << eventnames[i] << " : "<<accum_values[i]<<"\n";
|
||||
#endif
|
||||
cout << "Total vector time "<< (total_time*1e-9) << " baseline time "<<baseline_time*1e-9<<"\n";
|
||||
cout.flush();
|
||||
fflush(stdout);
|
||||
if(use_old_read_testcase)
|
||||
fclose(fptr);
|
||||
else
|
||||
ifptr.close();
|
||||
//cout << "Exceptions "<<exceptions_array[FE_INVALID]<< " "
|
||||
//<<exceptions_array[__FE_DENORM]<< " "
|
||||
//<<exceptions_array[FE_DIVBYZERO]<< " "
|
||||
//<<exceptions_array[FE_OVERFLOW]<< " "
|
||||
//<<exceptions_array[FE_UNDERFLOW]<< " "
|
||||
//<<exceptions_array[FE_INEXACT]<< "\n";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,4 +38,7 @@ enum ProcessorCapabilitiesEnum
|
|||
#define ENABLE_ALL_HARDWARE_FEATURES 0xFFFFFFFFFFFFFFFFull
|
||||
uint64_t get_machine_capabilities();
|
||||
void initialize_function_pointers(uint64_t mask=ENABLE_ALL_HARDWARE_FEATURES);
|
||||
|
||||
void do_compute(char* filename);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue