From 6e2dfa148c6ada3fb28d416814d9fb04539dd93f Mon Sep 17 00:00:00 2001 From: fenrir Date: Tue, 12 Nov 2024 23:42:53 +0900 Subject: [PATCH 1/4] Add precaution for use of BitCounter::ntz --- tool/util/bit_counter.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tool/util/bit_counter.h b/tool/util/bit_counter.h index 40469d098..5089fbf48 100644 --- a/tool/util/bit_counter.h +++ b/tool/util/bit_counter.h @@ -74,6 +74,8 @@ struct BitCounter { /** * Count rightmost zeros before the first one (Number of trailing zeros) + * Be careful, if input equals to 0, then total number of corresponding type bits + * will be returned like (unsigned int)0 => 32. * @param bits results */ static T ntz(const T &v) { From ba5e194726cc0f522f4b27d0ac91229209e61bee Mon Sep 17 00:00:00 2001 From: fenrir Date: Sun, 2 Feb 2025 22:09:57 +0900 Subject: [PATCH 2/4] Update actions/upload-artifact from v3 to v4 --- .github/workflows/CI_firmware_tools.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI_firmware_tools.yml b/.github/workflows/CI_firmware_tools.yml index d3c248470..5e77a993a 100644 --- a/.github/workflows/CI_firmware_tools.yml +++ b/.github/workflows/CI_firmware_tools.yml @@ -45,7 +45,7 @@ jobs: (cd ./tool && make clean all && (cd build_GCC && touch ${GITHUB_SHA}.commit && tar zvcf ubuntu.${GITHUB_REF##*/}.tar.gz *.out *.commit) ) (cd ./tool && BUILD_DIR=build_GCC_ARM CXX=arm-linux-gnueabihf-g++ make clean all && (cd build_GCC_ARM && touch ${GITHUB_SHA}.commit && tar zvcf raspi.${GITHUB_REF##*/}.tar.gz *.out *.commit) ) - name: upload_artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: path: | tool/build_*/*.tar.gz From 82edf59737eb11304af015b5bcae4c13b09dd771 Mon Sep 17 00:00:00 2001 From: fenrir Date: Wed, 18 Dec 2024 09:58:31 +0900 Subject: [PATCH 3/4] Add Ractor support to SylphideMath --- tool/swig/SylphideMath.i | 22 ++++++++++++++++++-- tool/swig/spec/SylphideMath_spec.rb | 31 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/tool/swig/SylphideMath.i b/tool/swig/SylphideMath.i index 0c1286802..8ed6e2255 100644 --- a/tool/swig/SylphideMath.i +++ b/tool/swig/SylphideMath.i @@ -5,8 +5,6 @@ %module SylphideMath -#define ENABLE_IOSTREAM 1 - %{ #include #include @@ -33,6 +31,12 @@ %include exception.i %include std_except.i +%init %{ +#ifdef HAVE_RB_EXT_RACTOR_SAFE + rb_ext_ractor_safe(true); +#endif +%} + %ignore native_exception; #if !defined(SWIGIMPORTED) %exceptionclass native_exception; @@ -1022,6 +1026,20 @@ struct MatrixUtil { } return res; } + + VALUE to_shareable() const { + Matrix_Frozen *ptr( + new Matrix_Frozen(*$self)); + VALUE res(SWIG_NewPointerObj( + ptr, + $descriptor(Matrix_Frozen *), + SWIG_POINTER_OWN)); + rb_obj_freeze(res); +%#if defined(HAVE_RB_EXT_RACTOR_SAFE) + RB_FL_SET(res, RUBY_FL_SHAREABLE); +%#endif + return res; + } #endif %typemap(in) Matrix > &output_L, diff --git a/tool/swig/spec/SylphideMath_spec.rb b/tool/swig/spec/SylphideMath_spec.rb index 9b0a3699b..fbd70a430 100644 --- a/tool/swig/spec/SylphideMath_spec.rb +++ b/tool/swig/spec/SylphideMath_spec.rb @@ -602,6 +602,37 @@ } end end + describe 'parallelization with Ractor' do + it "supports instantiation in sub Ractor" do + expect{ + rac = Ractor::new{ + mat_type, r, c = receive + # @see https://docs.ruby-lang.org/en/master/ractor_md.html#label-Return+value+of+a+block+for+Ractor.new + # When the block return value is available, ..., + # so any values can be sent with this communication path + # without any modification. + mat_type::new(r, c) + } + rac.send([mat_type, params[:rc]].flatten.freeze) + mat = rac.take + [:row_size, :column_size].zip(params[:rc]).each{|k, v| + expect(mat.send(k)).to eq(v) + } + }.not_to raise_error + end + it "supports messaging by using to_shareable between Ractors" do + expect{ + rac = Ractor::new{ + mat = receive + } + rac.send(mat_type::new(*params[:rc]).to_shareable) + mat = rac.take + [:row_size, :column_size].zip(params[:rc]).each{|k, v| + expect(mat.send(k)).to eq(v) + } + }.not_to raise_error + end + end if defined?(Ractor) end =begin From 92af11abac95d58a06fac5ffeb16fdcc03595d26 Mon Sep 17 00:00:00 2001 From: fenrir Date: Fri, 20 Dec 2024 15:01:35 +0900 Subject: [PATCH 4/4] Add Ractor support to Coordinate, GPS, and NavigationModel --- tool/swig/Coordinate.i | 6 ++++++ tool/swig/GPS.i | 6 ++++++ tool/swig/NavigationModel.i | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/tool/swig/Coordinate.i b/tool/swig/Coordinate.i index f91c73da7..be12c87a1 100644 --- a/tool/swig/Coordinate.i +++ b/tool/swig/Coordinate.i @@ -22,6 +22,12 @@ %feature("autodoc", "1"); +%init %{ +#ifdef HAVE_RB_EXT_RACTOR_SAFE + rb_ext_ractor_safe(true); +#endif +%} + %define MAKE_SETTER(name, type) %rename(%str(name ## =)) set_ ## name; type set_ ## name (const type &v) { diff --git a/tool/swig/GPS.i b/tool/swig/GPS.i index 37cb752bd..abc3a5b94 100644 --- a/tool/swig/GPS.i +++ b/tool/swig/GPS.i @@ -45,6 +45,12 @@ inline std::string to_string(const T &value){ %include exception.i %include std_except.i +%init %{ +#ifdef HAVE_RB_EXT_RACTOR_SAFE + rb_ext_ractor_safe(true); +#endif +%} + #if !defined(SWIGIMPORTED) %exceptionclass native_exception; %typemap(throws,noblock=1) native_exception { diff --git a/tool/swig/NavigationModel.i b/tool/swig/NavigationModel.i index a90e583bc..f52c9b5e7 100644 --- a/tool/swig/NavigationModel.i +++ b/tool/swig/NavigationModel.i @@ -29,6 +29,12 @@ %feature("autodoc", "1"); +%init %{ +#ifdef HAVE_RB_EXT_RACTOR_SAFE + rb_ext_ractor_safe(true); +#endif +%} + %define CONCRETIZE(type) %template(MagneticField) MagneticFieldGeneric; %template(IGRF11) MagneticFieldGeneric2;