-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Device Packing Optimization #1382
Changes from all commits
1b90f68
1404bfe
fd6f576
8ffd3d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,25 +145,25 @@ PackDataByIndexDevice ( buffer_unit_type * & buffer, | |
parallelDeviceEvents & events ) | ||
{ | ||
localIndex const numIndices = indices.size(); | ||
localIndex const unitSize = var.size() / var.size( 0 ) * sizeof( T ); | ||
|
||
buffer_unit_type * const devBuffer = buffer; | ||
localIndex const sliceSize = var.size() / var.size( 0 ); | ||
localIndex packedSize = numIndices * sliceSize * sizeof( T ); | ||
if( DO_PACKING ) | ||
{ | ||
T * devBuffer = reinterpret_cast< T * >( buffer ); | ||
parallelDeviceStream stream; | ||
events.emplace_back( forAll< parallelDeviceAsyncPolicy<> >( stream, numIndices, [=] GEOSX_DEVICE ( localIndex const ii ) | ||
events.emplace_back( forAll< parallelDevicePolicy< > >( stream, numIndices, [=] GEOSX_DEVICE ( localIndex const ii ) | ||
{ | ||
buffer_unit_type * threadBuffer = devBuffer + ii * unitSize; | ||
LvArray::forValuesInSlice( var[ indices[ ii ] ], [&threadBuffer] GEOSX_DEVICE ( T const & value ) | ||
T * threadBuffer = &devBuffer[ ii * sliceSize ]; | ||
LvArray::forValuesInSlice( var[ indices[ ii ] ], [&] GEOSX_DEVICE ( T const & value ) | ||
{ | ||
memcpy( threadBuffer, &value, sizeof( T ) ); | ||
threadBuffer += sizeof( T ); | ||
*threadBuffer = value; | ||
++threadBuffer; | ||
} ); | ||
} ) ); | ||
|
||
buffer += numIndices * unitSize; | ||
buffer += packedSize; | ||
} | ||
localIndex packedSize = numIndices * unitSize; | ||
|
||
return packedSize; | ||
} | ||
|
||
|
@@ -175,6 +175,18 @@ PackByIndexDevice ( buffer_unit_type * & buffer, | |
parallelDeviceEvents & events ) | ||
{ | ||
localIndex packedSize = PackPointerDevice< DO_PACKING >( buffer, var.strides(), NDIM ); | ||
size_t typeSize = sizeof( T ); | ||
uintptr_t misalignment = 0; | ||
if( DO_PACKING ) | ||
{ | ||
uintptr_t address = reinterpret_cast< uintptr_t >( buffer ); | ||
misalignment = address % typeSize; | ||
if( misalignment != 0 ) | ||
{ | ||
buffer += typeSize - misalignment; | ||
} | ||
} | ||
packedSize += typeSize - 1; | ||
packedSize += PackDataByIndexDevice< DO_PACKING >( buffer, var, indices, events ); | ||
return packedSize; | ||
} | ||
|
@@ -187,22 +199,22 @@ UnpackDataByIndexDevice ( buffer_unit_type const * & buffer, | |
parallelDeviceEvents & events ) | ||
{ | ||
localIndex numIndices = indices.size(); | ||
buffer_unit_type const * devBuffer = buffer; | ||
localIndex unitSize = var.size() / var.size( 0 ) * sizeof(T); | ||
localIndex sliceSize = var.size() / var.size( 0 ); | ||
localIndex unpackSize = numIndices * sliceSize * sizeof( T ); | ||
T const * devBuffer = reinterpret_cast< T const * >( buffer ); | ||
parallelDeviceStream stream; | ||
events.emplace_back( forAll< parallelDeviceAsyncPolicy<> >( stream, numIndices, [=] GEOSX_DEVICE ( localIndex const i ) | ||
events.emplace_back( forAll< parallelDeviceAsyncPolicy<> >( stream, numIndices, [=] GEOSX_DEVICE ( localIndex const ii ) | ||
{ | ||
buffer_unit_type const * threadBuffer = devBuffer + i * unitSize; | ||
LvArray::forValuesInSlice( var[ indices[ i ] ], [&threadBuffer] GEOSX_DEVICE ( T & value ) | ||
T const * threadBuffer = &devBuffer[ ii * sliceSize ]; | ||
LvArray::forValuesInSlice( var[ indices[ ii ] ], [&threadBuffer] GEOSX_DEVICE ( T & value ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about it later and you can only get rid of |
||
{ | ||
memcpy( &value, threadBuffer, sizeof( T ) ); | ||
threadBuffer += sizeof( T ); | ||
value = *threadBuffer; | ||
++threadBuffer; | ||
} ); | ||
} ) ); | ||
localIndex avSize = numIndices * unitSize; | ||
localIndex sizeOfPackedChars = avSize; | ||
buffer += avSize; | ||
return sizeOfPackedChars; | ||
|
||
buffer += unpackSize; | ||
return unpackSize; | ||
} | ||
|
||
template< typename T, int NDIM, int USD, typename T_INDICES > | ||
|
@@ -212,10 +224,18 @@ UnpackByIndexDevice ( buffer_unit_type const * & buffer, | |
T_INDICES const & indices, | ||
parallelDeviceEvents & events ) | ||
{ | ||
size_t typeSize = sizeof( T ); | ||
localIndex strides[NDIM]; | ||
localIndex sizeOfPackedChars = UnpackPointerDevice( buffer, strides, NDIM ); | ||
sizeOfPackedChars += UnpackDataByIndexDevice( buffer, var, indices, events ); | ||
return sizeOfPackedChars; | ||
localIndex unpackSize = UnpackPointerDevice( buffer, strides, NDIM ); | ||
uintptr_t address = reinterpret_cast< uintptr_t >( buffer ); | ||
uintptr_t misalignment = address % typeSize; | ||
if( misalignment != 0 ) | ||
{ | ||
buffer += typeSize - misalignment; | ||
} | ||
unpackSize += typeSize - 1; | ||
unpackSize += UnpackDataByIndexDevice( buffer, var, indices, events ); | ||
return unpackSize; | ||
} | ||
|
||
#define DECLARE_PACK_UNPACK( TYPE, NDIM, USD ) \ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should clean up this stream and events business later. We should not be creating a new stream for every field that we pack and we should probably do stream based synchronization instead of event based.