-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Intel-HLS/gp_ftz
Add support to set and get FTZ
- Loading branch information
Showing
8 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.intel.gkl.ftz; | ||
|
||
import com.intel.gkl.IntelGKLUtils; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.io.File; | ||
|
||
public class FTZ { | ||
private final static Logger logger = LogManager.getLogger(FTZ.class); | ||
|
||
private boolean isGklLoaded; | ||
|
||
public FTZ() { | ||
this(null); | ||
} | ||
|
||
public FTZ(File tmpDir) { | ||
isGklLoaded = IntelGKLUtils.load(tmpDir); | ||
|
||
if (!isGklLoaded) { | ||
logger.warn("FTZ control is not supported on this platform."); | ||
} | ||
} | ||
|
||
public boolean isSupported() { | ||
return isGklLoaded; | ||
} | ||
|
||
public boolean getFlushToZero() { | ||
return isGklLoaded && getFlushToZeroNative(); | ||
} | ||
|
||
public void setFlushToZero(boolean value) { | ||
if (isGklLoaded) { | ||
setFlushToZeroNative(value); | ||
} | ||
} | ||
|
||
private native boolean getFlushToZeroNative(); | ||
private native void setFlushToZeroNative(boolean value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
CPPFLAGS=-g -O3 -mavx -fPIC -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -I$(JAVA_HOME)/include/Darwin | ||
|
||
OUTPUT_OPTION=-MMD -MP -o $@ | ||
LDLIBS= | ||
|
||
TARGET = ftz.o | ||
|
||
SRC = $(wildcard *.cc) | ||
OBJ = $(SRC:.cc=.o) | ||
DEP = $(SRC:.cc=.d) | ||
|
||
all: javah $(TARGET) | ||
|
||
javah: | ||
javah -o ftz.h -cp ../../java com.intel.gkl.ftz.FTZ | ||
|
||
-include $(DEP) | ||
|
||
clean: | ||
rm -f $(OBJ) $(DEP) $(TARGET) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#if defined(_MSC_VER) | ||
#include <intrin.h> // SIMD intrinsics for Windows | ||
#else | ||
#include <x86intrin.h> // SIMD intrinsics for GCC | ||
#endif | ||
|
||
#include "ftz.h" | ||
|
||
// _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); | ||
|
||
/* | ||
* Class: com_intel_gkl_ftz_FTZ | ||
* Method: getFlushToZeroNative | ||
* Signature: ()Z | ||
*/ | ||
JNIEXPORT jboolean JNICALL Java_com_intel_gkl_ftz_FTZ_getFlushToZeroNative | ||
(JNIEnv *env, jobject obj) | ||
{ | ||
jboolean value = _MM_GET_FLUSH_ZERO_MODE() == _MM_FLUSH_ZERO_ON ? 1 : 0; | ||
return value; | ||
} | ||
|
||
/* | ||
* Class: com_intel_gkl_ftz_FTZ | ||
* Method: setFlushToZeroNative | ||
* Signature: (Z)V | ||
*/ | ||
JNIEXPORT void JNICALL Java_com_intel_gkl_ftz_FTZ_setFlushToZeroNative | ||
(JNIEnv *env, jobject obj, jboolean value) | ||
{ | ||
if (value) { | ||
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); | ||
} | ||
else { | ||
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_OFF); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.intel.gkl.ftz; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.testng.annotations.Test; | ||
|
||
public class FtzUnitTest { | ||
private final static Logger log = LogManager.getLogger(FtzUnitTest.class); | ||
|
||
@Test(enabled = true) | ||
public void simpleTest() { | ||
FTZ ftz = new FTZ(); | ||
assert(ftz.isSupported()); | ||
|
||
log.info("Test setting FTZ"); | ||
boolean value = false; | ||
ftz.setFlushToZero(true); | ||
value = ftz.getFlushToZero(); | ||
assert(value == true); | ||
|
||
log.info("Test clearing FTZ"); | ||
value = true; | ||
ftz.setFlushToZero(false); | ||
value = ftz.getFlushToZero(); | ||
assert(value == false); | ||
} | ||
|
||
class ChildThread extends Thread { | ||
boolean ftzValue; | ||
|
||
public void run() { | ||
FTZ ftz = new FTZ(); | ||
assert(ftz.isSupported()); | ||
|
||
ftzValue = ftz.getFlushToZero(); | ||
log.info("Child thread FTZ = " + ftzValue); | ||
} | ||
} | ||
|
||
@Test(enabled = true) | ||
public void childThreadTest() { | ||
FTZ ftz = new FTZ(); | ||
assert (ftz.isSupported()); | ||
|
||
log.info("Parent setting FTZ = true"); | ||
|
||
boolean value = false; | ||
ftz.setFlushToZero(true); | ||
value = ftz.getFlushToZero(); | ||
assert(value == true); | ||
|
||
ChildThread childThread = new ChildThread(); | ||
|
||
childThread.start(); | ||
try { | ||
childThread.join(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
assert(childThread.ftzValue == false); | ||
} | ||
} |