From e729fe6363833f5c982b43bf2a11f170f4800430 Mon Sep 17 00:00:00 2001 From: hamidrezanorouzi Date: Wed, 12 Apr 2023 23:37:05 +0330 Subject: [PATCH] bug fix binrayIO and sorting for cuda build --- src/phasicFlow/containers/Field/Field.cpp | 38 ++--- src/phasicFlow/containers/Vector/Vector.cpp | 132 ++++++++++-------- src/phasicFlow/containers/Vector/Vector.hpp | 6 +- .../containers/VectorHD/VectorDual.hpp | 13 +- .../containers/VectorHD/VectorSingle.hpp | 37 ++--- .../pointStructure/mortonIndexing.cpp | 11 +- 6 files changed, 130 insertions(+), 107 deletions(-) diff --git a/src/phasicFlow/containers/Field/Field.cpp b/src/phasicFlow/containers/Field/Field.cpp index a2b5ec9b..5569ea9b 100644 --- a/src/phasicFlow/containers/Field/Field.cpp +++ b/src/phasicFlow/containers/Field/Field.cpp @@ -82,25 +82,16 @@ bool pFlow::Field::readNonUniform return false; } - this->clear(); - if(is.isBinary() && !std::is_same_v) + VectorType::readVector(is, flen); + is.readEndStatement("readField"); + if( this->size() != flen ) { - this->resize(flen); - is.read(reinterpret_cast(this->data()), this->size()*sizeof(T)); - is.readEndStatement("readField"); + ioErrorInFile( is.name(), is.lineNumber() ) << + " expected " << flen << " elements, but supplied "<< + this->size() << " elements in file "<< is.name() <size() != flen ) - { - ioErrorInFile( is.name(), is.lineNumber() ) << - " expected " << flen << " elements, but supplied "<< - this->size() << " elements in file "<< is.name() <::readField template class VectorField, class T, class PropType> bool pFlow::Field::writeField(iOstream& os)const { + os.writeWordKeyword(fieldKey_) << nonUniform__<size()<) - { - os.write(reinterpret_cast(this->data()), this->size()*sizeof(T)); - } - else - { - VectorType::write(os); - } + + VectorType::write(os); + os.endEntry(); + return true; } diff --git a/src/phasicFlow/containers/Vector/Vector.cpp b/src/phasicFlow/containers/Vector/Vector.cpp index b9d76479..7c0c9db3 100644 --- a/src/phasicFlow/containers/Vector/Vector.cpp +++ b/src/phasicFlow/containers/Vector/Vector.cpp @@ -28,59 +28,70 @@ pFlow::Vector::Vector(iIstream& is) template bool pFlow::Vector::readVector ( - iIstream& is + iIstream& is, + size_t len ) { - this->clear(); + - is.fatalCheck(FUNCTION_NAME); - - token firstToken(is); - - T val{}; - if( firstToken.isPunctuation() ) // start of vector + if(is.isBinary() && !std::is_same_v) { - if(firstToken != token::BEGIN_LIST) + this->resize(len); + is.read(reinterpret_cast(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 << "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 - << "expected token "<< token::BEGIN_LIST - << " but found "<< firstToken ; - return false; - } + + return true; } @@ -91,30 +102,35 @@ bool pFlow::Vector::writeVector iOstream& os ) const { - - - auto len = size(); - auto stride = getVectorStride(len); - // start of - os << token::BEGIN_LIST; - label i = 0; - while( i) + { + os.write(reinterpret_cast(this->data()), this->size()*sizeof(T)); + } + else { - os << this->operator[](i++); - for(label j=0; joperator[](i++); + + os << this->operator[](i++); + for(label j=0; joperator[](i++); + } + + if(i vecFromFile; - if( !vecFromFile.read(is) ) return false; + if( !vecFromFile.readVector(is,len) ) return false; this->assign(vecFromFile); return true; } + FUNCTION_H + bool read(iIstream& is) + { + return readVector(is); + } + FUNCTION_H bool write(iOstream& os) const { diff --git a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp index 7dfd4105..e0d14127 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp @@ -570,30 +570,25 @@ public: size_t newSize = indices.size(); viewType sortedView("sortedView", newSize); - if constexpr (isHostAccessible_) - { - auto h_indices = indices.hostView(); - Kokkos::parallel_for( + using policy = Kokkos::RangePolicy< + execution_space, + Kokkos::IndexType >; + + auto d_indices = indices.deviceView(); + auto d_view = view_; + Kokkos::parallel_for( "sortItems", newSize, 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(); + setSize(newSize); copy(deviceVector(), sortedView); + return; } @@ -835,16 +830,24 @@ public: //// - IO operations FUNCTION_H - bool read(iIstream& is) + bool readVector( + iIstream& is, + size_t len=0) { Vector vecFromFile; - if( !vecFromFile.read(is) ) return false; + if( !vecFromFile.readVector(is,len) ) return false; this->assign(vecFromFile); return true; } + FUNCTION_H + bool read(iIstream& is) + { + return readVector(is); + } + FUNCTION_H bool write(iOstream& os)const { diff --git a/src/phasicFlow/structuredData/pointStructure/mortonIndexing.cpp b/src/phasicFlow/structuredData/pointStructure/mortonIndexing.cpp index c3b55e55..63969747 100644 --- a/src/phasicFlow/structuredData/pointStructure/mortonIndexing.cpp +++ b/src/phasicFlow/structuredData/pointStructure/mortonIndexing.cpp @@ -21,6 +21,7 @@ Licence: #include "mortonIndexing.hpp" #include "cells.hpp" +#include "streams.hpp" bool pFlow::getSortedIndex( box boundingBox, @@ -37,6 +38,8 @@ bool pFlow::getSortedIndex( ViewType1D mortonCode("mortonCode", activeRange.second); + output<<"before first kernel"<>; int32 numActive = 0; @@ -52,13 +55,17 @@ bool pFlow::getSortedIndex( sumToUpdate++; }else { - mortonCode[i] = xyzToMortonCode64(-1,-1,-1); + mortonCode[i] = xyzToMortonCode64 + ( + static_cast(-1), + static_cast(-1), + static_cast(-1) + ); } }, numActive ); - permuteSort( mortonCode, activeRange.first,