Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Dec 2023 17:03:36 GMT
From:      Po-Chuan Hsieh <sunpoet@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: 1cf964ed6e83 - main - misc/caffe: Fix build with protobuf 22+
Message-ID:  <202312141703.3BEH3aS1017093@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by sunpoet:

URL: https://cgit.FreeBSD.org/ports/commit/?id=1cf964ed6e83f5ff2b26c72f9afc7c346a5fda89

commit 1cf964ed6e83f5ff2b26c72f9afc7c346a5fda89
Author:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
AuthorDate: 2023-12-14 16:22:37 +0000
Commit:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
CommitDate: 2023-12-14 17:03:06 +0000

    misc/caffe: Fix build with protobuf 22+
---
 misc/caffe/Makefile             |  5 +--
 misc/caffe/files/patch-protobuf | 77 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/misc/caffe/Makefile b/misc/caffe/Makefile
index 040ebe90ed01..02ca395819c9 100644
--- a/misc/caffe/Makefile
+++ b/misc/caffe/Makefile
@@ -36,8 +36,8 @@ RUN_DEPENDS=	${PYNUMPY} \
 		${PYTHON_PKGNAMEPREFIX}scipy>0:science/py-scipy@${PY_FLAVOR} \
 		${PYTHON_PKGNAMEPREFIX}six>0:devel/py-six@${PY_FLAVOR}
 
-USES=		cmake fortran pkgconfig python
-USE_CXXSTD=	c++14
+USES=		cmake compiler:c++17-lang fortran localbase:ldflags pkgconfig python
+USE_CXXSTD=	c++17
 USE_LDCONFIG=	yes
 
 USE_GITHUB=	yes
@@ -46,6 +46,7 @@ GH_ACCOUNT=	BVLC
 CMAKE_ARGS=	-DBLAS=Open \
 		-DPYTHON_EXECUTABLE=${PYTHON_CMD} \
 		-DFREEBSD_PYTHONPREFIX_SITELIBDIR=${PYTHONPREFIX_SITELIBDIR}
+LDFLAGS+=	-lpython${PYTHON_VER}
 
 PORTSCOUT=	limit:^[0-9].*[0-9]$$ # should begin and end with a digit to prevent tags like rcnn-release and rc5
 
diff --git a/misc/caffe/files/patch-protobuf b/misc/caffe/files/patch-protobuf
new file mode 100644
index 000000000000..b1139c7e1bb7
--- /dev/null
+++ b/misc/caffe/files/patch-protobuf
@@ -0,0 +1,77 @@
+--- src/caffe/layers/hdf5_data_layer.cpp.orig	2020-02-13 07:20:36 UTC
++++ src/caffe/layers/hdf5_data_layer.cpp
+@@ -7,7 +7,9 @@ TODO:
+   :: don't forget to update hdf5_daa_layer.cu accordingly
+ - add ability to shuffle filenames if flag is set
+ */
++#include <algorithm>
+ #include <fstream>  // NOLINT(readability/streams)
++#include <random>
+ #include <string>
+ #include <vector>
+ 
+@@ -38,6 +40,9 @@ void HDF5DataLayer<Dtype>::LoadHDF5FileData(const char
+   const int MIN_DATA_DIM = 1;
+   const int MAX_DATA_DIM = INT_MAX;
+ 
++  std::random_device rd;
++  std::mt19937 g(rd());
++
+   for (int i = 0; i < top_size; ++i) {
+     hdf_blobs_[i] = shared_ptr<Blob<Dtype> >(new Blob<Dtype>());
+     // Allow reshape here, as we are loading data not params
+@@ -62,7 +67,7 @@ void HDF5DataLayer<Dtype>::LoadHDF5FileData(const char
+ 
+   // Shuffle if needed.
+   if (this->layer_param_.hdf5_data_param().shuffle()) {
+-    std::random_shuffle(data_permutation_.begin(), data_permutation_.end());
++    std::shuffle(data_permutation_.begin(), data_permutation_.end(), g);
+     DLOG(INFO) << "Successfully loaded " << hdf_blobs_[0]->shape(0)
+                << " rows (shuffled)";
+   } else {
+@@ -73,6 +78,8 @@ void HDF5DataLayer<Dtype>::LoadHDF5FileData(const char
+ template <typename Dtype>
+ void HDF5DataLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
+       const vector<Blob<Dtype>*>& top) {
++  std::random_device rd;
++  std::mt19937 g(rd());
+   // Refuse transformation parameters since HDF5 is totally generic.
+   CHECK(!this->layer_param_.has_transform_param()) <<
+       this->type() << " does not transform data.";
+@@ -105,7 +112,7 @@ void HDF5DataLayer<Dtype>::LayerSetUp(const vector<Blo
+ 
+   // Shuffle if needed.
+   if (this->layer_param_.hdf5_data_param().shuffle()) {
+-    std::random_shuffle(file_permutation_.begin(), file_permutation_.end());
++    std::shuffle(file_permutation_.begin(), file_permutation_.end(), g);
+   }
+ 
+   // Load the first HDF5 file and initialize the line counter.
+@@ -138,14 +145,16 @@ bool HDF5DataLayer<Dtype>::Skip() {
+ 
+ template<typename Dtype>
+ void HDF5DataLayer<Dtype>::Next() {
++  std::random_device rd;
++  std::mt19937 g(rd());
+   if (++current_row_ == hdf_blobs_[0]->shape(0)) {
+     if (num_files_ > 1) {
+       ++current_file_;
+       if (current_file_ == num_files_) {
+         current_file_ = 0;
+         if (this->layer_param_.hdf5_data_param().shuffle()) {
+-          std::random_shuffle(file_permutation_.begin(),
+-                              file_permutation_.end());
++          std::shuffle(file_permutation_.begin(),
++                              file_permutation_.end(), g);
+         }
+         DLOG(INFO) << "Looping around to first file.";
+       }
+@@ -154,7 +163,7 @@ void HDF5DataLayer<Dtype>::Next() {
+     }
+     current_row_ = 0;
+     if (this->layer_param_.hdf5_data_param().shuffle())
+-      std::random_shuffle(data_permutation_.begin(), data_permutation_.end());
++      std::shuffle(data_permutation_.begin(), data_permutation_.end(), g);
+   }
+   offset_++;
+ }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202312141703.3BEH3aS1017093>