Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
solverstack
ScalFMM
Commits
efb2f716
Commit
efb2f716
authored
Apr 03, 2015
by
BRAMAS Berenger
Browse files
Use inc method to access memory part in particles blocks
parent
5b32a526
Changes
3
Hide whitespace changes
Inline
Side-by-side
Src/GroupTree/Core/FGroupOfParticles.hpp
View file @
efb2f716
...
...
@@ -29,10 +29,12 @@ class FGroupOfParticles {
//< The real number of particles allocated
FSize
nbParticlesAllocatedInGroup
;
//< Starting point of position
size_t
offsetPosition
;
//< Bytes difference/offset between position
size_t
position
Offset
;
size_t
position
sLeadingDim
;
//< Bytes difference/offset between attributes
size_t
attribute
Offset
;
size_t
attribute
LeadingDim
;
//< The total number of particles in the group
FSize
nbParticlesInGroup
;
};
...
...
@@ -97,19 +99,20 @@ public:
blockHeader
(
nullptr
),
blockIndexesTable
(
nullptr
),
leafHeader
(
nullptr
),
nbParticlesInGroup
(
0
),
attributesBuffer
(
nullptr
),
deleteBuffer
(
false
){
// Move the pointers to the correct position
blockHeader
=
reinterpret_cast
<
BlockHeader
*>
(
memoryBuffer
);
blockIndexesTable
=
reinterpret_cast
<
int
*>
(
memoryBuffer
+
sizeof
(
BlockHeader
));
leafHeader
=
reinterpret_cast
<
LeafHeader
*>
(
memoryBuffer
+
sizeof
(
BlockHeader
)
+
(
blockHeader
->
blockIndexesTableSize
*
sizeof
(
int
)));
blockHeader
=
reinterpret_cast
<
BlockHeader
*>
(
inBuffer
);
inBuffer
+=
sizeof
(
BlockHeader
);
blockIndexesTable
=
reinterpret_cast
<
int
*>
(
inBuffer
);
inBuffer
+=
(
blockHeader
->
blockIndexesTableSize
*
sizeof
(
int
));
leafHeader
=
reinterpret_cast
<
LeafHeader
*>
(
inBuffer
);
// Init particle pointers
blockHeader
->
positionOffset
=
(
sizeof
(
FReal
)
*
blockHeader
->
nbParticlesAllocatedInGroup
);
particlePosition
[
0
]
=
reinterpret_cast
<
FReal
*>
((
reinterpret_cast
<
size_t
>
(
leafHeader
+
blockHeader
->
numberOfLeavesInBlock
)
+
MemoryAlignementBytes
-
1
)
&
~
(
MemoryAlignementBytes
-
1
));
FAssertLF
(
blockHeader
->
positionsLeadingDim
==
(
sizeof
(
FReal
)
*
blockHeader
->
nbParticlesAllocatedInGroup
)
);
particlePosition
[
0
]
=
reinterpret_cast
<
FReal
*>
(
memoryBuffer
+
blockHeader
->
offsetPosition
);
particlePosition
[
1
]
=
(
particlePosition
[
0
]
+
blockHeader
->
nbParticlesAllocatedInGroup
);
particlePosition
[
2
]
=
(
particlePosition
[
1
]
+
blockHeader
->
nbParticlesAllocatedInGroup
);
// Redirect pointer to data
blockHeader
->
attribute
Offset
=
(
sizeof
(
AttributeClass
)
*
blockHeader
->
nbParticlesAllocatedInGroup
);
FAssertLF
(
blockHeader
->
attribute
LeadingDim
=
=
(
sizeof
(
AttributeClass
)
*
blockHeader
->
nbParticlesAllocatedInGroup
)
)
;
AttributeClass
*
symAttributes
=
(
AttributeClass
*
)(
&
particlePosition
[
2
][
blockHeader
->
nbParticlesAllocatedInGroup
]);
for
(
unsigned
idxAttribute
=
0
;
idxAttribute
<
NbSymbAttributes
;
++
idxAttribute
){
particleAttributes
[
idxAttribute
]
=
symAttributes
;
...
...
@@ -155,26 +158,31 @@ public:
memset
(
memoryBuffer
,
0
,
memoryToAlloc
);
// Move the pointers to the correct position
blockHeader
=
reinterpret_cast
<
BlockHeader
*>
(
memoryBuffer
);
blockIndexesTable
=
reinterpret_cast
<
int
*>
(
memoryBuffer
+
sizeof
(
BlockHeader
));
leafHeader
=
reinterpret_cast
<
LeafHeader
*>
(
memoryBuffer
+
sizeof
(
BlockHeader
)
+
(
blockIndexesTableSize
*
sizeof
(
int
)));
unsigned
char
*
bufferPtr
=
memoryBuffer
;
blockHeader
=
reinterpret_cast
<
BlockHeader
*>
(
bufferPtr
);
bufferPtr
+=
sizeof
(
BlockHeader
);
blockIndexesTable
=
reinterpret_cast
<
int
*>
(
bufferPtr
);
bufferPtr
+=
sizeof
(
BlockHeader
)
+
(
blockIndexesTableSize
*
sizeof
(
int
));
leafHeader
=
reinterpret_cast
<
LeafHeader
*>
(
bufferPtr
);
// Init header
blockHeader
->
startingIndex
=
inStartingIndex
;
blockHeader
->
endingIndex
=
inEndingIndex
;
blockHeader
->
numberOfLeavesInBlock
=
inNumberOfLeaves
;
blockHeader
->
blockIndexesTableSize
=
blockIndexesTableSize
;
blockHeader
->
blockIndexesTableSize
=
blockIndexesTableSize
;
blockHeader
->
nbParticlesAllocatedInGroup
=
nbParticlesAllocatedInGroup
;
// Init particle pointers
blockHeader
->
position
Offset
=
(
sizeof
(
FReal
)
*
nbParticlesAllocatedInGroup
);
blockHeader
->
position
sLeadingDim
=
(
sizeof
(
FReal
)
*
nbParticlesAllocatedInGroup
);
particlePosition
[
0
]
=
reinterpret_cast
<
FReal
*>
((
reinterpret_cast
<
size_t
>
(
leafHeader
+
inNumberOfLeaves
)
+
MemoryAlignementBytes
-
1
)
&
~
(
MemoryAlignementBytes
-
1
));
particlePosition
[
1
]
=
(
particlePosition
[
0
]
+
nbParticlesAllocatedInGroup
);
particlePosition
[
2
]
=
(
particlePosition
[
1
]
+
nbParticlesAllocatedInGroup
);
blockHeader
->
offsetPosition
=
size_t
(
particlePosition
[
0
])
-
size_t
(
memoryBuffer
);
// Redirect pointer to data
blockHeader
->
attribute
Offset
=
(
sizeof
(
AttributeClass
)
*
nbParticlesAllocatedInGroup
);
blockHeader
->
attribute
LeadingDim
=
(
sizeof
(
AttributeClass
)
*
nbParticlesAllocatedInGroup
);
AttributeClass
*
symAttributes
=
(
AttributeClass
*
)(
&
particlePosition
[
2
][
blockHeader
->
nbParticlesAllocatedInGroup
]);
for
(
unsigned
idxAttribute
=
0
;
idxAttribute
<
NbSymbAttributes
;
++
idxAttribute
){
...
...
@@ -182,8 +190,8 @@ public:
symAttributes
+=
blockHeader
->
nbParticlesAllocatedInGroup
;
}
attributesBuffer
=
(
AttributeClass
*
)
FAlignedMemory
::
AllocateBytes
<
MemoryAlignementBytes
>
(
blockHeader
->
attribute
Offset
*
NbAttributesPerParticle
);
memset
(
attributesBuffer
,
0
,
blockHeader
->
attribute
Offset
*
NbAttributesPerParticle
);
attributesBuffer
=
(
AttributeClass
*
)
FAlignedMemory
::
AllocateBytes
<
MemoryAlignementBytes
>
(
blockHeader
->
attribute
LeadingDim
*
NbAttributesPerParticle
);
memset
(
attributesBuffer
,
0
,
blockHeader
->
attribute
LeadingDim
*
NbAttributesPerParticle
);
for
(
unsigned
idxAttribute
=
0
;
idxAttribute
<
NbAttributesPerParticle
;
++
idxAttribute
){
particleAttributes
[
idxAttribute
+
NbSymbAttributes
]
=
&
attributesBuffer
[
idxAttribute
*
nbParticlesAllocatedInGroup
];
}
...
...
@@ -224,7 +232,7 @@ public:
/** The the size of the allocated buffer */
size_t
getAttributesBufferSizeInByte
()
const
{
return
blockHeader
->
attribute
Offset
*
NbAttributesPerParticle
;
return
blockHeader
->
attribute
LeadingDim
*
NbAttributesPerParticle
;
}
/** To know if the object will delete the memory block */
...
...
@@ -290,9 +298,9 @@ public:
const
int
id
=
blockIndexesTable
[
idxLeafPtr
];
ParticlesAttachedClass
leaf
(
leafHeader
[
id
].
nbParticles
,
particlePosition
[
0
]
+
leafHeader
[
id
].
offSet
,
blockHeader
->
position
Offset
,
(
attributesBuffer
?
particleAttributes
[
NbSymbAttributes
]
+
leafHeader
[
id
].
offSet
:
nullptr
),
blockHeader
->
attribute
Offset
);
blockHeader
->
position
sLeadingDim
,
(
attributesBuffer
?
particleAttributes
[
NbSymbAttributes
]
+
leafHeader
[
id
].
offSet
:
nullptr
),
blockHeader
->
attribute
LeadingDim
);
function
(
&
leaf
);
}
}
...
...
@@ -306,9 +314,9 @@ public:
const
int
id
=
blockIndexesTable
[
leafIndex
-
blockHeader
->
startingIndex
];
return
ParticlesAttachedClass
(
leafHeader
[
id
].
nbParticles
,
particlePosition
[
0
]
+
leafHeader
[
id
].
offSet
,
blockHeader
->
position
Offset
,
blockHeader
->
position
sLeadingDim
,
(
attributesBuffer
?
particleAttributes
[
NbSymbAttributes
]
+
leafHeader
[
id
].
offSet
:
nullptr
),
blockHeader
->
attribute
Offset
);
blockHeader
->
attribute
LeadingDim
);
}
return
ParticlesAttachedClass
();
}
...
...
Src/GroupTree/Cuda/FCudaGroupOfParticles.hpp
View file @
efb2f716
...
...
@@ -17,10 +17,12 @@ class FCudaGroupOfParticles {
//< The real number of particles allocated
FSize
nbParticlesAllocatedInGroup
;
//< Starting point of position
size_t
offsetPosition
;
//< Bytes difference/offset between position
size_t
position
Offset
;
size_t
position
sLeadingDim
;
//< Bytes difference/offset between attributes
size_t
attribute
Offset
;
size_t
attribute
LeadingDim
;
//< The total number of particles in the group
FSize
nbParticlesInGroup
;
};
...
...
@@ -87,14 +89,13 @@ public:
leafHeader
=
reinterpret_cast
<
LeafHeader
*>
(
memoryBuffer
+
sizeof
(
BlockHeader
)
+
(
blockHeader
->
blockIndexesTableSize
*
sizeof
(
int
)));
// Init particle pointers
blockHeader
->
positionOffset
=
(
sizeof
(
FReal
)
*
blockHeader
->
nbParticlesAllocatedInGroup
);
particlePosition
[
0
]
=
reinterpret_cast
<
FReal
*>
((
reinterpret_cast
<
size_t
>
(
leafHeader
+
blockHeader
->
numberOfLeavesInBlock
)
+
MemoryAlignementBytes
-
1
)
&
~
(
MemoryAlignementBytes
-
1
));
// Assert blockHeader->positionsLeadingDim == (sizeof(FReal) * blockHeader->nbParticlesAllocatedInGroup);
particlePosition
[
0
]
=
reinterpret_cast
<
FReal
*>
(
memoryBuffer
+
blockHeader
->
offsetPosition
);
particlePosition
[
1
]
=
(
particlePosition
[
0
]
+
blockHeader
->
nbParticlesAllocatedInGroup
);
particlePosition
[
2
]
=
(
particlePosition
[
1
]
+
blockHeader
->
nbParticlesAllocatedInGroup
);
// Redirect pointer to data
blockHeader
->
attribute
Offset
=
(
sizeof
(
AttributeClass
)
*
blockHeader
->
nbParticlesAllocatedInGroup
);
// Assert
blockHeader->attribute
LeadingDim =
= (sizeof(AttributeClass) * blockHeader->nbParticlesAllocatedInGroup);
AttributeClass
*
symAttributes
=
(
AttributeClass
*
)(
&
particlePosition
[
2
][
blockHeader
->
nbParticlesAllocatedInGroup
]);
for
(
unsigned
idxAttribute
=
0
;
idxAttribute
<
NbSymbAttributes
;
++
idxAttribute
){
particleAttributes
[
idxAttribute
]
=
symAttributes
;
...
...
@@ -150,9 +151,9 @@ public:
const
int
id
=
blockIndexesTable
[
leafIndex
-
blockHeader
->
startingIndex
];
return
ParticlesAttachedClass
(
leafHeader
[
id
].
nbParticles
,
particlePosition
[
0
]
+
leafHeader
[
id
].
offSet
,
blockHeader
->
position
Offset
,
blockHeader
->
position
sLeadingDim
,
(
attributesBuffer
?
particleAttributes
[
NbSymbAttributes
]
+
leafHeader
[
id
].
offSet
:
nullptr
),
blockHeader
->
attribute
Offset
);
blockHeader
->
attribute
LeadingDim
);
}
return
ParticlesAttachedClass
();
}
...
...
Src/GroupTree/TestKernel/FTestKernel.cl
View file @
efb2f716
...
...
@@ -267,10 +267,12 @@ struct FOpenCLGroupOfParticlesBlockHeader{
//<
The
real
number
of
particles
allocated
FSize
nbParticlesAllocatedInGroup
;
//<
Starting
point
of
position
size_t
offsetPosition
;
//<
Bytes
difference/offset
between
position
size_t
position
Offset
;
size_t
position
sLeadingDim
;
//<
Bytes
difference/offset
between
attributes
size_t
attribute
Offset
;
size_t
attribute
LeadingDim
;
//<
The
total
number
of
particles
in
the
group
FSize
nbParticlesInGroup
;
}__attribute__
((
aligned
(
DefaultStructAlign
)))
;
...
...
@@ -312,19 +314,20 @@ struct FOpenCLGroupOfParticles BuildFOpenCLGroupOfParticles(__global unsigned ch
group.memoryBuffer
=
(
inBuffer
)
;
//
Move
the
pointers
to
the
correct
position
group.blockHeader
=
((
__global
struct
FOpenCLGroupOfParticlesBlockHeader*
)
group.memoryBuffer
)
;
group.blockIndexesTable
=
((
__global
int*
)(
group.memoryBuffer+sizeof
(
struct
FOpenCLGroupOfParticlesBlockHeader
)))
;
group.leafHeader
=
((
__global
struct
FOpenCLGroupOfParticlesLeafHeader*
)(
group.memoryBuffer+sizeof
(
struct
FOpenCLGroupOfParticlesBlockHeader
)
+
(
group.blockHeader->blockIndexesTableSize*sizeof
(
int
))))
;
group.blockHeader
=
((
__global
struct
FOpenCLGroupOfParticlesBlockHeader*
)
inBuffer
)
;
inBuffer
+=
sizeof
(
struct
FOpenCLGroupOfParticlesBlockHeader
)
;
group.blockIndexesTable
=
((
__global
int*
)
inBuffer
)
;
inBuffer
+=
(
group.blockHeader->blockIndexesTableSize*sizeof
(
int
))
;
group.leafHeader
=
((
__global
struct
FOpenCLGroupOfParticlesLeafHeader*
)
inBuffer
)
;
//
Init
particle
pointers
group.blockHeader->positionOffset
=
(
sizeof
(
FReal
)
*
group.blockHeader->nbParticlesAllocatedInGroup
)
;
group.particlePosition[0]
=
(
__global
FReal*
)
((
((
size_t
)(
group.leafHeader
+
group.blockHeader->numberOfLeavesInBlock
))
+FOpenCLGroupOfParticlesMemoryAlignementBytes-1
)
&
~
(
FOpenCLGroupOfParticlesMemoryAlignementBytes-1
))
;
//
Assert
group.blockHeader->positionsLeadingDim
==
(
sizeof
(
FReal
)
*
group.blockHeader->nbParticlesAllocatedInGroup
)
;
group.particlePosition[0]
=
(
__global
FReal*
)
(
group.memoryBuffer
+
group.offsetPosition
)
;
group.particlePosition[1]
=
(
group.particlePosition[0]
+
group.blockHeader->nbParticlesAllocatedInGroup
)
;
group.particlePosition[2]
=
(
group.particlePosition[1]
+
group.blockHeader->nbParticlesAllocatedInGroup
)
;
//
Redirect
pointer
to
data
group.blockHeader->attribute
Offset
=
(
sizeof
(
FParticleValueClass
)
*
group.blockHeader->nbParticlesAllocatedInGroup
)
;
//
Assert
group.blockHeader->attribute
LeadingDim
=
=
(
sizeof
(
FParticleValueClass
)
*
group.blockHeader->nbParticlesAllocatedInGroup
)
;
__global
unsigned
char*
previousPointer
=
((
__global
unsigned
char*
)(
group.particlePosition[2]
+
group.blockHeader->nbParticlesAllocatedInGroup
))
;
for
(
unsigned
idxAttribute
=
0
; idxAttribute < NbSymbAttributes ; ++idxAttribute){
group.particleAttributes[idxAttribute]
=
((
__global
FParticleValueClass*
)
previousPointer
)
;
...
...
@@ -367,9 +370,9 @@ struct FOpenCLGroupAttachedLeaf FOpenCLGroupOfParticles_getLeaf(struct FOpenCLGr
const
int
id
=
group->blockIndexesTable[leafIndex
-
group->blockHeader->startingIndex]
;
return
BuildFOpenCLGroupAttachedLeaf
(
group->leafHeader[id].nbParticles,
group->particlePosition[0]
+
group->leafHeader[id].offSet,
group->blockHeader->position
Offset
,
group->blockHeader->position
sLeadingDim
,
(
group->attributesBuffer?group->particleAttributes[NbSymbAttributes]
+
group->leafHeader[id].offSet:NULLPTR
)
,
group->blockHeader->attribute
Offset
)
;
group->blockHeader->attribute
LeadingDim
)
;
}
return
EmptyFOpenCLGroupAttachedLeaf
()
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment