bug fix binrayIO and sorting for cuda build

This commit is contained in:
hamidrezanorouzi 2023-04-12 23:37:05 +03:30
parent b6360643ee
commit e729fe6363
6 changed files with 130 additions and 107 deletions

View File

@ -82,26 +82,17 @@ bool pFlow::Field<VectorField, T, PropType>::readNonUniform
return false; return false;
} }
this->clear(); VectorType::readVector(is, flen);
if(is.isBinary() && !std::is_same_v<T,word>) is.readEndStatement("readField");
if( this->size() != flen )
{ {
this->resize(flen); ioErrorInFile( is.name(), is.lineNumber() ) <<
is.read(reinterpret_cast<char*>(this->data()), this->size()*sizeof(T)); " expected " << flen << " elements, but supplied "<<
is.readEndStatement("readField"); this->size() << " elements in file "<< is.name() <<endl;
} return false;
else
{
VectorType::read(is);
is.readEndStatement("readField");
if( this->size() != flen )
{
ioErrorInFile( is.name(), is.lineNumber() ) <<
" expected " << flen << " elements, but supplied "<<
this->size() << " elements in file "<< is.name() <<endl;
return false;
}
} }
return true; return true;
} }
@ -178,17 +169,14 @@ bool pFlow::Field<VectorField, T, PropType>::readField
template<template<class, class> class VectorField, class T, class PropType> template<template<class, class> class VectorField, class T, class PropType>
bool pFlow::Field<VectorField, T, PropType>::writeField(iOstream& os)const bool pFlow::Field<VectorField, T, PropType>::writeField(iOstream& os)const
{ {
os.writeWordKeyword(fieldKey_) << nonUniform__<<endl; os.writeWordKeyword(fieldKey_) << nonUniform__<<endl;
os<< this->size()<<endl; os<< this->size()<<endl;
if( os.isBinary() && !std::is_same_v<T,word>)
{ VectorType::write(os);
os.write(reinterpret_cast<const char*>(this->data()), this->size()*sizeof(T));
}
else
{
VectorType::write(os);
}
os.endEntry(); os.endEntry();
return true; return true;
} }

View File

@ -28,59 +28,70 @@ pFlow::Vector<T, Allocator>::Vector(iIstream& is)
template<typename T, typename Allocator> template<typename T, typename Allocator>
bool pFlow::Vector<T, Allocator>::readVector bool pFlow::Vector<T, Allocator>::readVector
( (
iIstream& is iIstream& is,
size_t len
) )
{ {
this->clear();
is.fatalCheck(FUNCTION_NAME);
token firstToken(is); if(is.isBinary() && !std::is_same_v<T,word>)
T val{};
if( firstToken.isPunctuation() ) // start of vector
{ {
if(firstToken != token::BEGIN_LIST) this->resize(len);
is.read(reinterpret_cast<char*>(this->data()), this->size()*sizeof(T));
}
else
{
this->clear();
is.fatalCheck(FUNCTION_NAME);
token firstToken(is);
T val{};
if( firstToken.isPunctuation() ) // start of vector
{
if(firstToken != token::BEGIN_LIST)
{
warningInFunction
<< "expected token "<< token::BEGIN_LIST
<< " but found "<< firstToken ;
return false;
}
token lastToken(is);
is.fatalCheck(FUNCTION_NAME);
while
( !(
lastToken.isPunctuation()
&& lastToken == token::END_LIST
)
)
{
is.putBack(lastToken);
is >> val;
this->push_back(val);
is >> lastToken;
is.fatalCheck(FUNCTION_NAME);
}
} else
{ {
warningInFunction warningInFunction
<< "expected token "<< token::BEGIN_LIST << "expected token "<< token::BEGIN_LIST
<< " but found "<< firstToken ; << " but found "<< firstToken ;
return false; return false;
} }
token lastToken(is);
is.fatalCheck(FUNCTION_NAME);
while
( !(
lastToken.isPunctuation()
&& lastToken == token::END_LIST
)
)
{
is.putBack(lastToken);
is >> val;
this->push_back(val);
is >> lastToken;
is.fatalCheck(FUNCTION_NAME);
}
} else
{
warningInFunction
<< "expected token "<< token::BEGIN_LIST
<< " but found "<< firstToken ;
return false;
} }
return true; return true;
} }
@ -91,31 +102,36 @@ bool pFlow::Vector<T, Allocator>::writeVector
iOstream& os iOstream& os
) const ) const
{ {
auto len = size();
auto stride = getVectorStride(len);
// start of // start of
os << token::BEGIN_LIST; if( os.isBinary() && !std::is_same_v<T,word>)
label i = 0; {
while( i<len ) os.write(reinterpret_cast<const char*>(this->data()), this->size()*sizeof(T));
}
else
{ {
os << this->operator[](i++); auto len = size();
for(label j=0; j<stride-1 && i<len; j++ ) auto stride = getVectorStride(len);
os << token::BEGIN_LIST;
label i = 0;
while( i<len )
{ {
os << token::SPACE << this->operator[](i++);
os << this->operator[](i++);
for(label j=0; j<stride-1 && i<len; j++ )
{
os << token::SPACE << this->operator[](i++);
}
if(i<len)
os<< token::NL;
} }
if(i<len) os << token::END_LIST;
os<< token::NL;
os.check(FUNCTION_NAME);
} }
os << token::END_LIST;
os.check(FUNCTION_NAME);
return true; return true;
} }

View File

@ -291,6 +291,8 @@ public:
return *this; return *this;
} }
const word& name()const const word& name()const
{ {
return name_; return name_;
@ -372,9 +374,7 @@ public:
// from iIstream and free size // from iIstream and free size
Vector(iIstream& is); Vector(iIstream& is);
//bool readVector(iIstream & is, size_t len); bool readVector(iIstream& is, size_t len=0);
bool readVector(iIstream& is);
bool writeVector(iOstream& os) const; bool writeVector(iOstream& os) const;

View File

@ -567,6 +567,7 @@ public:
sortedView[i] = dVec[d_indices[i]]; sortedView[i] = dVec[d_indices[i]];
} }
); );
Kokkos::fence(); Kokkos::fence();
setSize(newSize); setSize(newSize);
copy(deviceVector(), sortedView); copy(deviceVector(), sortedView);
@ -931,16 +932,24 @@ public:
//// - IO operations //// - IO operations
FUNCTION_H FUNCTION_H
bool read(iIstream& is) bool readVector(
iIstream& is,
size_t len=0)
{ {
Vector<T> vecFromFile; Vector<T> vecFromFile;
if( !vecFromFile.read(is) ) return false; if( !vecFromFile.readVector(is,len) ) return false;
this->assign(vecFromFile); this->assign(vecFromFile);
return true; return true;
} }
FUNCTION_H
bool read(iIstream& is)
{
return readVector(is);
}
FUNCTION_H FUNCTION_H
bool write(iOstream& os) const bool write(iOstream& os) const
{ {

View File

@ -570,30 +570,25 @@ public:
size_t newSize = indices.size(); size_t newSize = indices.size();
viewType sortedView("sortedView", newSize); viewType sortedView("sortedView", newSize);
if constexpr (isHostAccessible_) using policy = Kokkos::RangePolicy<
{ execution_space,
auto h_indices = indices.hostView(); Kokkos::IndexType<int32> >;
Kokkos::parallel_for(
auto d_indices = indices.deviceView();
auto d_view = view_;
Kokkos::parallel_for(
"sortItems", "sortItems",
newSize, newSize,
LAMBDA_HD(int32 i){ LAMBDA_HD(int32 i){
sortedView[i] = view_[h_indices[i]]; sortedView(i) = d_view(d_indices(i));
}); });
}else
{
auto d_indices = indices.deviceView();
Kokkos::parallel_for(
"sortItems",
newSize,
LAMBDA_HD(int32 i){
sortedView[i] = view_[d_indices[i]];
});
}
Kokkos::fence(); Kokkos::fence();
setSize(newSize); setSize(newSize);
copy(deviceVector(), sortedView); copy(deviceVector(), sortedView);
return; return;
} }
@ -835,16 +830,24 @@ public:
//// - IO operations //// - IO operations
FUNCTION_H FUNCTION_H
bool read(iIstream& is) bool readVector(
iIstream& is,
size_t len=0)
{ {
Vector<T> vecFromFile; Vector<T> vecFromFile;
if( !vecFromFile.read(is) ) return false; if( !vecFromFile.readVector(is,len) ) return false;
this->assign(vecFromFile); this->assign(vecFromFile);
return true; return true;
} }
FUNCTION_H
bool read(iIstream& is)
{
return readVector(is);
}
FUNCTION_H FUNCTION_H
bool write(iOstream& os)const bool write(iOstream& os)const
{ {

View File

@ -21,6 +21,7 @@ Licence:
#include "mortonIndexing.hpp" #include "mortonIndexing.hpp"
#include "cells.hpp" #include "cells.hpp"
#include "streams.hpp"
bool pFlow::getSortedIndex( bool pFlow::getSortedIndex(
box boundingBox, box boundingBox,
@ -37,6 +38,8 @@ bool pFlow::getSortedIndex(
ViewType1D<uint64_t> mortonCode("mortonCode", activeRange.second); ViewType1D<uint64_t> mortonCode("mortonCode", activeRange.second);
output<<"before first kernel"<<endl;;
using rpMorton = using rpMorton =
Kokkos::RangePolicy<Kokkos::IndexType<int32>>; Kokkos::RangePolicy<Kokkos::IndexType<int32>>;
int32 numActive = 0; int32 numActive = 0;
@ -52,13 +55,17 @@ bool pFlow::getSortedIndex(
sumToUpdate++; sumToUpdate++;
}else }else
{ {
mortonCode[i] = xyzToMortonCode64(-1,-1,-1); mortonCode[i] = xyzToMortonCode64
(
static_cast<uint64_t>(-1),
static_cast<uint64_t>(-1),
static_cast<uint64_t>(-1)
);
} }
}, },
numActive numActive
); );
permuteSort( permuteSort(
mortonCode, mortonCode,
activeRange.first, activeRange.first,