Skip to content

Commit

Permalink
Buffer allocation size match to jlong
Browse files Browse the repository at this point in the history
  • Loading branch information
jjfumero committed Mar 10, 2022
1 parent 4f34abc commit 26e5155
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 74 deletions.
44 changes: 22 additions & 22 deletions levelZeroLib/src/levelZeroContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_Lev
/*
* Class: uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext
* Method: zeMemAllocShared_native
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;Luk/ac/manchester/tornado/drivers/spirv/levelzero/ZeHostMemAllocDesc;IIJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroBufferInteger;)I
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;Luk/ac/manchester/tornado/drivers/spirv/levelzero/ZeHostMemAllocDesc;JJJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroBufferInteger;)I
*/
JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext_zeMemAllocShared_1native
(JNIEnv *env, jobject object, jlong javaContextPtr, jobject javaDeviceMemAllocDesc, jobject javaHostMemAllocDesc, jint bufferSize, jint aligmnent, jlong javaDeviceHandler, jobject javaLevelZeroBuffer) {
(JNIEnv *env, jobject object, jlong javaContextPtr, jobject javaDeviceMemAllocDesc, jobject javaHostMemAllocDesc, jlong bufferSize, jlong aligmnent, jlong javaDeviceHandler, jobject javaLevelZeroBuffer) {

ze_context_handle_t context = reinterpret_cast<ze_context_handle_t>(javaContextPtr);
ze_device_handle_t device = reinterpret_cast<ze_device_handle_t>(javaDeviceHandler);
Expand Down Expand Up @@ -362,10 +362,10 @@ JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_Lev
/*
* Class: uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext
* Method: zeMemAllocShared_nativeByte
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;Luk/ac/manchester/tornado/drivers/spirv/levelzero/ZeHostMemAllocDesc;IIJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroByteBuffer;)I
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;Luk/ac/manchester/tornado/drivers/spirv/levelzero/ZeHostMemAllocDesc;JJJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroByteBuffer;)I
*/
JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext_zeMemAllocShared_1nativeByte
(JNIEnv *env, jobject object, jlong javaContextPtr, jobject javaDeviceMemAllocDesc, jobject javaHostMemAllocDesc, jint bufferSize, jint aligmnent, jlong javaDeviceHandler, jobject javaLevelZeroBuffer) {
(JNIEnv *env, jobject object, jlong javaContextPtr, jobject javaDeviceMemAllocDesc, jobject javaHostMemAllocDesc, jlong bufferSize, jlong aligmnent, jlong javaDeviceHandler, jobject javaLevelZeroBuffer) {

ze_context_handle_t context = reinterpret_cast<ze_context_handle_t>(javaContextPtr);
ze_device_handle_t device = reinterpret_cast<ze_device_handle_t>(javaDeviceHandler);
Expand Down Expand Up @@ -409,10 +409,10 @@ JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_Lev
/*
* Class: uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext
* Method: zeMemAllocDevice_native
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;IIJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroByteBuffer;)I
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;JJJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroByteBuffer;)I
*/
JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext_zeMemAllocDevice_1native
(JNIEnv *env, jobject object, jlong javaContextPtr, jobject javaDeviceMemAllocDesc, jint allocSize, jint alignment, jlong javaDeviceHandler, jobject javaLevelZeroBuffer) {
(JNIEnv *env, jobject object, jlong javaContextPtr, jobject javaDeviceMemAllocDesc, jlong allocSize, jlong alignment, jlong javaDeviceHandler, jobject javaLevelZeroBuffer) {

ze_context_handle_t context = reinterpret_cast<ze_context_handle_t>(javaContextPtr);
ze_device_handle_t device = reinterpret_cast<ze_device_handle_t>(javaDeviceHandler);
Expand All @@ -438,22 +438,22 @@ JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_Lev
LOG_ZE_JNI("zeMemAllocDevice", result)

// Set Buffer Pointer and attributes
jfieldID fieldBufferSize = env->GetFieldID(javaBufferClass, "size", "I");
jfieldID alignmentField = env->GetFieldID(javaBufferClass, "alignment", "I");
jfieldID fieldBufferSize = env->GetFieldID(javaBufferClass, "size", "J");
jfieldID alignmentField = env->GetFieldID(javaBufferClass, "alignment", "J");
env->SetLongField(javaLevelZeroBuffer, fieldBuffer, reinterpret_cast<ulong>(buffer));
env->SetIntField(javaLevelZeroBuffer, fieldBufferSize, allocSize);
env->SetIntField(javaLevelZeroBuffer, alignmentField, alignment);
env->SetLongField(javaLevelZeroBuffer, fieldBufferSize, allocSize);
env->SetLongField(javaLevelZeroBuffer, alignmentField, alignment);

return result;
}

/*
* Class: uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext
* Method: zeMemAllocDevice_nativeLong
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;IIJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroBufferLong;)I
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;JJJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroBufferLong;)I
*/
JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext_zeMemAllocDevice_1nativeLong
(JNIEnv * env, jobject object, jlong javaContextPtr, jobject javaDeviceMemAllocDesc, jint allocSize, jint alignment, jlong javaDeviceHandler, jobject javaLevelZeroBuffer) {
(JNIEnv * env, jobject object, jlong javaContextPtr, jobject javaDeviceMemAllocDesc, jlong allocSize, jlong alignment, jlong javaDeviceHandler, jobject javaLevelZeroBuffer) {
ze_context_handle_t context = reinterpret_cast<ze_context_handle_t>(javaContextPtr);
ze_device_handle_t device = reinterpret_cast<ze_device_handle_t>(javaDeviceHandler);

Expand All @@ -478,11 +478,11 @@ JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_Lev
LOG_ZE_JNI("zeMemAllocDevice - [LONG]", result)

// Set Buffer Pointer and attributes
jfieldID fieldBufferSize = env->GetFieldID(javaBufferClass, "size", "I");
jfieldID alignmentField = env->GetFieldID(javaBufferClass, "alignment", "I");
jfieldID fieldBufferSize = env->GetFieldID(javaBufferClass, "size", "J");
jfieldID alignmentField = env->GetFieldID(javaBufferClass, "alignment", "J");
env->SetLongField(javaLevelZeroBuffer, fieldBuffer, reinterpret_cast<ulong>(buffer));
env->SetIntField(javaLevelZeroBuffer, fieldBufferSize, allocSize);
env->SetIntField(javaLevelZeroBuffer, alignmentField, alignment);
env->SetLongField(javaLevelZeroBuffer, fieldBufferSize, allocSize);
env->SetLongField(javaLevelZeroBuffer, alignmentField, alignment);

return result;
}
Expand Down Expand Up @@ -797,10 +797,10 @@ JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_Lev
/*
* Class: uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext
* Method: zeMemAllocHost_native
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeHostMemAllocDesc;IILuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroByteBuffer;)I
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeHostMemAllocDesc;JJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroByteBuffer;)I
*/
JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext_zeMemAllocHost_1native
(JNIEnv *env, jobject, jlong javaContextPtr, jobject javaHostMemAllocDesc, jint allocSize, jint alignment, jobject javaLevelZeroBuffer) {
(JNIEnv *env, jobject, jlong javaContextPtr, jobject javaHostMemAllocDesc, jlong allocSize, jlong alignment, jobject javaLevelZeroBuffer) {


ze_context_handle_t context = reinterpret_cast<ze_context_handle_t>(javaContextPtr);
Expand Down Expand Up @@ -829,11 +829,11 @@ JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_Lev
LOG_ZE_JNI("zeMemAllocHost", result);

// Set Buffer Pointer and attributes
jfieldID fieldBufferSize = env->GetFieldID(javaBufferClass, "size", "I");
jfieldID alignmentField = env->GetFieldID(javaBufferClass, "alignment", "I");
jfieldID fieldBufferSize = env->GetFieldID(javaBufferClass, "size", "J");
jfieldID alignmentField = env->GetFieldID(javaBufferClass, "alignment", "J");
env->SetLongField(javaLevelZeroBuffer, fieldBuffer, reinterpret_cast<jlong>(buffer));
env->SetIntField(javaLevelZeroBuffer, fieldBufferSize, allocSize);
env->SetIntField(javaLevelZeroBuffer, alignmentField, alignment);
env->SetLongField(javaLevelZeroBuffer, fieldBufferSize, allocSize);
env->SetLongField(javaLevelZeroBuffer, alignmentField, alignment);

return result;
}
20 changes: 10 additions & 10 deletions levelZeroLib/src/levelZeroContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,34 @@ JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_Lev
/*
* Class: uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext
* Method: zeMemAllocShared_native
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;Luk/ac/manchester/tornado/drivers/spirv/levelzero/ZeHostMemAllocDesc;IIJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroBufferInteger;)I
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;Luk/ac/manchester/tornado/drivers/spirv/levelzero/ZeHostMemAllocDesc;JJJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroBufferInteger;)I
*/
JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext_zeMemAllocShared_1native
(JNIEnv *, jobject, jlong, jobject, jobject, jint, jint, jlong, jobject);
(JNIEnv *, jobject, jlong, jobject, jobject, jlong, jlong, jlong, jobject);

/*
* Class: uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext
* Method: zeMemAllocShared_nativeByte
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;Luk/ac/manchester/tornado/drivers/spirv/levelzero/ZeHostMemAllocDesc;IIJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroByteBuffer;)I
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;Luk/ac/manchester/tornado/drivers/spirv/levelzero/ZeHostMemAllocDesc;JJJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroByteBuffer;)I
*/
JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext_zeMemAllocShared_1nativeByte
(JNIEnv *, jobject, jlong, jobject, jobject, jint, jint, jlong, jobject);
(JNIEnv *, jobject, jlong, jobject, jobject, jlong, jlong, jlong, jobject);

/*
* Class: uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext
* Method: zeMemAllocDevice_native
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;IIJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroByteBuffer;)I
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;JJJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroByteBuffer;)I
*/
JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext_zeMemAllocDevice_1native
(JNIEnv *, jobject, jlong, jobject, jint, jint, jlong, jobject);
(JNIEnv *, jobject, jlong, jobject, jlong, jlong, jlong, jobject);

/*
* Class: uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext
* Method: zeMemAllocDevice_nativeLong
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;IIJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroBufferLong;)I
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeDeviceMemAllocDesc;JJJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroBufferLong;)I
*/
JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext_zeMemAllocDevice_1nativeLong
(JNIEnv *, jobject, jlong, jobject, jint, jint, jlong, jobject);
(JNIEnv *, jobject, jlong, jobject, jlong, jlong, jlong, jobject);

/*
* Class: uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext
Expand Down Expand Up @@ -171,10 +171,10 @@ JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_Lev
/*
* Class: uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext
* Method: zeMemAllocHost_native
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeHostMemAllocDesc;IILuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroByteBuffer;)I
* Signature: (JLuk/ac/manchester/tornado/drivers/spirv/levelzero/ZeHostMemAllocDesc;JJLuk/ac/manchester/tornado/drivers/spirv/levelzero/LevelZeroByteBuffer;)I
*/
JNIEXPORT jint JNICALL Java_uk_ac_manchester_tornado_drivers_spirv_levelzero_LevelZeroContext_zeMemAllocHost_1native
(JNIEnv *, jobject, jlong, jobject, jint, jint, jobject);
(JNIEnv *, jobject, jlong, jobject, jlong, jlong, jobject);
#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public long getPtrBuffer() {
return ptrBuffer;
}

public void memset(int value, int bufferSize) {
public void memset(int value, long bufferSize) {
memset_native(this, value, bufferSize);
}

Expand All @@ -48,7 +48,7 @@ public void initPtr() {
this.ptrBuffer = -1;
}

native void memset_native(LevelZeroBufferInteger javaBuffer, int value, int bufferSize);
native void memset_native(LevelZeroBufferInteger javaBuffer, int value, long bufferSize);

native boolean isEqual(long bufferAPtr, long bufferBPtr, int size);
native boolean isEqual(long bufferAPtr, long bufferBPtr, long size);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
public class LevelZeroBufferLong {

private long ptrBuffer;
private int size;
private int alignment;
private long size;
private long alignment;

public LevelZeroBufferLong() {
this.ptrBuffer = -1;
Expand All @@ -44,11 +44,11 @@ public long getPtrBuffer() {
return this.ptrBuffer;
}

public int getSize() {
public long getSize() {
return this.size;
}

public int getAlignment() {
public long getAlignment() {
return this.alignment;
}

Expand Down Expand Up @@ -79,7 +79,7 @@ public void copy(long[] array) {
copy_native(this.ptrBuffer, array);
}

private native long[] getLongBuffer_native(long ptrBuffer, int size);
private native long[] getLongBuffer_native(long ptrBuffer, long size);

public long[] getLongBuffer() {
return getLongBuffer_native(this.ptrBuffer, this.size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
public class LevelZeroByteBuffer {

private long ptrBuffer;
private int size;
private int alignment;
private long size;
private long alignment;

public LevelZeroByteBuffer() {
this.ptrBuffer = -1;
Expand All @@ -44,11 +44,11 @@ public long getPtrBuffer() {
return this.ptrBuffer;
}

public int getSize() {
public long getSize() {
return this.size;
}

public int getAlignment() {
public long getAlignment() {
return this.alignment;
}

Expand Down Expand Up @@ -78,14 +78,14 @@ public void initPtr() {

/**
* Copies the input array into the LevelZeroBuffer
*
*
* @param array
*/
public void copy(byte[] array) {
copy_native(this.ptrBuffer, array);
}

private native byte[] getByteBuffer_native(long ptrBuffer, int size);
private native byte[] getByteBuffer_native(long ptrBuffer, long size);

public byte[] getByteBuffer() {
return getByteBuffer_native(this.ptrBuffer, this.size);
Expand Down
Loading

0 comments on commit 26e5155

Please sign in to comment.