Skip to content

Commit

Permalink
Merge pull request #344 from WireCell/dnnroi-prod
Browse files Browse the repository at this point in the history
Compiler error and some DNNROI related updates
  • Loading branch information
HaiwangYu authored Oct 7, 2024
2 parents e84e054 + 0b7cedc commit fa806da
Show file tree
Hide file tree
Showing 30 changed files with 177 additions and 39 deletions.
1 change: 0 additions & 1 deletion aux/inc/WireCellAux/FrameSync.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
namespace WireCell::Aux {

class FrameSync : Aux::Logger, public IFrameMerge {
bool m_flushing{false};
public:

FrameSync(const size_t multiplicity = 2);
Expand Down
2 changes: 1 addition & 1 deletion aux/test/check_tensordm_pctree_speed.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int test_file(const std::string& fname,
{
ExecMon em("pc tree from tensor DM file");

auto& pm = PluginManager::instance();
auto& pm [[maybe_unused]] = PluginManager::instance();
assert(pm.add("WireCellSio"));

auto cobj = Factory::lookup_tn<IConfigurable>("TensorFileSource");
Expand Down
2 changes: 1 addition & 1 deletion aux/test/test_idft.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void fwdrev(IDFT::pointer dft, int id, int ntimes, int size)
dft->inv2d(freq.data(), inter.data(), nstrides, stride);

--ntimes;
auto tot = Waveform::sum(inter);
auto tot [[maybe_unused]] = Waveform::sum(inter);
assert(std::real(tot) == 0);
}
//std::cerr << "finished " << id << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions gen/test/test_random.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ double test_speed_direct(size_t ndraws)
struct Xorsh {
unsigned long x{123456789}, y{362436069}, z{521288629};
typedef size_t result_type;
static size_t min() { return 0; }
static size_t max() { return std::numeric_limits<long>::max(); }
static constexpr size_t min() { return 0; }
static constexpr size_t max() { return std::numeric_limits<long>::max(); }

unsigned long operator()() {
unsigned long t;
Expand Down
6 changes: 3 additions & 3 deletions img/src/BlobDepoFill.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,22 @@ slice_and_dice_depos(Log::logptr_t& log,
// Add slice nodes
const size_t nsbins = sbins.nbins();
for (size_t idx = 0; idx < nsbins; ++idx) {
const auto gidx = boost::add_vertex({idx, 's'}, gr);
const auto gidx [[maybe_unused]] = boost::add_vertex({idx, 's'}, gr);
assert(gidx == idx);
}

// Add depo nodes
const size_t ndepos = depos.size();
for (size_t idx=0; idx<ndepos; ++idx) {
const auto gidx = boost::add_vertex({idx, 'd'}, gr);
const auto gidx [[maybe_unused]] = boost::add_vertex({idx, 'd'}, gr);
assert(gidx == idx + nsbins);
}

// Add wire nodes
const auto pbins = pimpos.region_binning();
const size_t nwires = pbins.nbins();
for (size_t idx = 0; idx < nwires; ++idx) {
const auto gidx = boost::add_vertex({idx, 'w'}, gr);
const auto gidx [[maybe_unused]] = boost::add_vertex({idx, 'w'}, gr);
assert(gidx == idx + nsbins + ndepos);
}

Expand Down
2 changes: 1 addition & 1 deletion img/src/MultiAlgBlobClustering.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ bool MultiAlgBlobClustering::operator()(const input_pointer& ints, output_pointe
}

const auto& intens = *ints->tensors();
auto root_live = std::move(as_pctree(intens, inpath + "/live"));
auto root_live = as_pctree(intens, inpath + "/live");
if (!root_live) {
log->error("Failed to get dead point cloud tree from \"{}\"", inpath);
raise<ValueError>("Failed to get live point cloud tree from \"%s\"", inpath);
Expand Down
1 change: 1 addition & 0 deletions pytorch/inc/WireCellPytorch/TorchContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

#include "WireCellIface/ISemaphore.h"

#include <torch/script.h>

namespace WireCell::Pytorch {
Expand Down
2 changes: 1 addition & 1 deletion pytorch/inc/WireCellPytorch/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ namespace WireCell {
}; // namespace Pytorch
} // namespace WireCell

#endif // WIRECELLPYTORCH_UTIL
#endif // WIRECELLPYTORCH_UTIL
2 changes: 1 addition & 1 deletion pytorch/src/DNNROIFinding.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ bool Pytorch::DNNROIFinding::operator()(const IFrame::pointer& inframe, IFrame::
log->debug(tk(fmt::format("call={} inference done", m_save_count)));

// tensor to eigen
Eigen::Map<Eigen::ArrayXXf> out_e(output[0][0].data<float>(), output.size(3), output.size(2));
Eigen::Map<Eigen::ArrayXXf> out_e(output[0][0].data_ptr<float>(), output.size(3), output.size(2));
auto mask_e = Array::upsample(out_e, m_cfg.tick_per_slice, 0);

log->debug(tk(fmt::format("call={} tensor2eigen", m_save_count)));
Expand Down
2 changes: 1 addition & 1 deletion pytorch/src/Util.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ITensorSet::pointer Pytorch::to_itensor(const std::vector<torch::IValue> &inputs
size_t nbyte = 4;
for (auto n : shape) nbyte *= n;
auto data = (float *) st->data();
memcpy(data, (float *) ten[0][0].data<float>(), nbyte);
memcpy(data, (float *) ten[0][0].data_ptr<float>(), nbyte);
itv->push_back(ITensor::pointer(st));
++ind;
}
Expand Down
20 changes: 10 additions & 10 deletions pytorch/test/check_chunking.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ int main(int argc, const char* argv[])

// Disable gradient computation, use like a mutex lock
torch::NoGradGuard no_grad;
if (false) {
torch::Tensor a = torch::rand({1, 2, 3, 3});
std::cout << "Tensor shape: " << a.sizes() << std::endl;
std::cout << a << std::endl;
// Extract the desired sub-tensor using the slice method
torch::Tensor sub_tensor = a.index({torch::indexing::Slice(), torch::indexing::Slice(1, 2), torch::indexing::Slice(), torch::indexing::Slice()});
// Print the shape of the extracted tensor
std::cout << "Sub-tensor shape: " << sub_tensor.sizes() << std::endl;
std::cout << sub_tensor << std::endl;
}
// if (false) {
// torch::Tensor a = torch::rand({1, 2, 3, 3});
// std::cout << "Tensor shape: " << a.sizes() << std::endl;
// std::cout << a << std::endl;
// // Extract the desired sub-tensor using the slice method
// torch::Tensor sub_tensor = a.index({torch::indexing::Slice(), torch::indexing::Slice(1, 2), torch::indexing::Slice(), torch::indexing::Slice()});
// // Print the shape of the extracted tensor
// std::cout << "Sub-tensor shape: " << sub_tensor.sizes() << std::endl;
// std::cout << sub_tensor << std::endl;
// }
{
Eigen::MatrixXf ch_eigen = Eigen::MatrixXf::Identity(4, 4);
std::cout << "matrix: \n" << ch_eigen << std::endl;
Expand Down
3 changes: 0 additions & 3 deletions root/test/test_draw_raygrid.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ using namespace std;
using spdlog::info;
using spdlog::warn;

const int ndepos = 10;
const int neles = 10;
const double pitch_magnitude = 5;
const double gaussian = 3;
const double border = 10;
const double width = 100;
const double height = 100;
Expand Down
2 changes: 1 addition & 1 deletion root/test/test_misconfigure.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ TH2F* plot_frame(MultiPdf& pdf, IFrame::pointer frame, std::string name, double
int main(int argc, char* argv[])
{
PluginManager& pm = PluginManager::instance();
auto aux_pi = pm.add("WireCellAux");
auto aux_pi [[maybe_unused]] = pm.add("WireCellAux");
assert(aux_pi);
pm.add("WireCellGen");
pm.add("WireCellRoot");
Expand Down
2 changes: 2 additions & 0 deletions sigproc/inc/WireCellSigProc/OmnibusSigProc.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ namespace WireCell {
std::string m_frame_tag{"sigproc"};

bool m_use_roi_debug_mode{false};
bool m_save_negtive_charge{false};
bool m_use_roi_refinement{true};
std::string m_tight_lf_tag{"tight_lf"};
std::string m_loose_lf_tag{"loose_lf"};
Expand All @@ -233,6 +234,7 @@ namespace WireCell {
std::string m_extend_roi_tag{"extend_roi"};

bool m_use_multi_plane_protection{false};
bool m_do_not_mp_protect_traditional{false};
std::string m_mp3_roi_tag{"mp3_roi"};
std::string m_mp2_roi_tag{"mp2_roi"};
double m_mp_th1{1000.};
Expand Down
9 changes: 8 additions & 1 deletion sigproc/src/OmnibusSigProc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ void OmnibusSigProc::configure(const WireCell::Configuration& config)
m_frame_tag = get(config, "frame_tag", m_frame_tag);

m_use_roi_debug_mode = get(config, "use_roi_debug_mode", m_use_roi_debug_mode);
m_save_negtive_charge = get(config, "save_negtive_charge", m_save_negtive_charge);
m_use_roi_refinement = get(config, "use_roi_refinement", m_use_roi_refinement);
m_tight_lf_tag = get(config, "tight_lf_tag", m_tight_lf_tag);
m_loose_lf_tag = get(config, "loose_lf_tag", m_loose_lf_tag);
Expand All @@ -172,6 +173,7 @@ void OmnibusSigProc::configure(const WireCell::Configuration& config)
m_extend_roi_tag = get(config, "extend_roi_tag", m_extend_roi_tag);

m_use_multi_plane_protection = get<bool>(config, "use_multi_plane_protection", m_use_multi_plane_protection);
m_do_not_mp_protect_traditional = get<bool>(config, "do_not_mp_protect_traditional", m_do_not_mp_protect_traditional);
m_mp3_roi_tag = get(config, "mp3_roi_tag", m_mp3_roi_tag);
m_mp2_roi_tag = get(config, "mp2_roi_tag", m_mp2_roi_tag);
m_mp_th1 = get(config, "mp_th1", m_mp_th1);
Expand Down Expand Up @@ -432,7 +434,7 @@ void OmnibusSigProc::save_data(
const float q = m_r_data[plane](och.wire, itick);
// charge.at(itick) = q > 0.0 ? q : 0.0;
// charge.at(itick) = q ;
if (m_use_roi_debug_mode) {
if (m_use_roi_debug_mode && m_save_negtive_charge) {
charge.at(itick) = q; // debug mode: save all decons
}
else { // nominal: threshold at zero.
Expand Down Expand Up @@ -1599,6 +1601,11 @@ bool OmnibusSigProc::operator()(const input_pointer& in, output_pointer& out)
}
save_mproi(*itraces, mp3_roi_traces, iplane, roi_refine.get_mp3_rois());
save_mproi(*itraces, mp2_roi_traces, iplane, roi_refine.get_mp2_rois());
if (m_do_not_mp_protect_traditional) {
// clear mp after saving to itraces
roi_refine.get_mp3_rois().clear();
roi_refine.get_mp2_rois().clear();
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions sigproc/src/ROI_refinement.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ namespace WireCell {
const int nbounds_layers = 2);

typedef std::multimap<std::pair<int, int>, std::pair<int, int>> MapMPROI;
MapMPROI get_mp2_rois() const { return mp_rois; }
MapMPROI get_mp3_rois() const { return proteced_rois; }
const MapMPROI& get_mp2_rois() const { return mp_rois; }
MapMPROI get_mp2_rois() { return mp_rois; }
const MapMPROI& get_mp3_rois() const { return proteced_rois; }
MapMPROI& get_mp3_rois() { return proteced_rois; }

void CleanUpROIs(int plane);
void generate_merge_ROIs(int plane);
Expand Down
34 changes: 34 additions & 0 deletions sigproc/test/test_abs_speed.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <complex>
#include <chrono>
#include <iostream>
#include <cmath>

int main() {
std::complex<double> x(3.0, 4.0); // Example complex number

int numIterations = 1e9;

// Measure the time taken by std::abs(x)
auto start = std::chrono::high_resolution_clock::now();
double absSum = 0;
for (int i = 0; i < numIterations; i++) {
absSum += std::abs(x);
}
auto end = std::chrono::high_resolution_clock::now();
auto absDuration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();

// Measure the time taken by std::sqrt(std::norm(x))
start = std::chrono::high_resolution_clock::now();
double sqrtSum = 0;
for (int i = 0; i < numIterations; i++) {
sqrtSum += std::sqrt(std::norm(x));
}
end = std::chrono::high_resolution_clock::now();
auto sqrtDuration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();

// Print the results
std::cout << "std::abs(x) duration: " << absDuration << " milliseconds, sum = " << absSum << std::endl;
std::cout << "std::sqrt(std::norm(x)) duration: " << sqrtDuration << " milliseconds, sum = " << sqrtSum << std::endl;

return 0;
}
22 changes: 22 additions & 0 deletions util/inc/WireCellUtil/Eigen.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,35 @@
#ifndef WIRECELL_EIGEN
#define WIRECELL_EIGEN

#ifdef __clang__
# if defined(__has_warning)
# define HAS_WARNING(warning) __has_warning(warning)
# else
# define HAS_WARNING(warning) 1
# endif
#else
# define HAS_WARNING(warning) 1
#endif

#if HAS_WARNING("-Wmaybe-uninitialized")
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wmaybe-uninitialized"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
#include <Eigen/Core>
#if HAS_WARNING("-Wmaybe-uninitialized")
#pragma GCC diagnostic pop
#endif

#if HAS_WARNING("-Wignored-attributes")
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wignored-attributes"
#pragma GCC diagnostic ignored "-Wignored-attributes"
#endif
#include <Eigen/Sparse>
#if HAS_WARNING("-Wignored-attributes")
#pragma GCC diagnostic pop
#endif

#include <Eigen/Eigenvalues>

Expand Down
16 changes: 16 additions & 0 deletions util/inc/WireCellUtil/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,29 @@
// #define BOOST_ALLOW_DEPRECATED_HEADERS 1
#include <boost/graph/graph_traits.hpp>

#ifdef __clang__
# if defined(__has_warning)
# define HAS_WARNING(warning) __has_warning(warning)
# else
# define HAS_WARNING(warning) 1
# endif
#else
# define HAS_WARNING(warning) 1
#endif

#if HAS_WARNING("-Wmaybe-uninitialized")
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wmaybe-uninitialized"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/graph/connected_components.hpp>

#if HAS_WARNING("-Wmaybe-uninitialized")
#pragma GCC diagnostic pop
#endif

#include <boost/graph/filtered_graph.hpp>
#include <boost/graph/copy.hpp>
Expand Down
12 changes: 12 additions & 0 deletions util/inc/WireCellUtil/MultiArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@
#ifndef WIRECELL_MULTIARRAY
#define WIRECELL_MULTIARRAY

#ifdef __clang__
# if defined(__has_warning)
# define HAS_WARNING(warning) __has_warning(warning)
# else
# define HAS_WARNING(warning) 1
# endif
#else
# define HAS_WARNING(warning) 1
#endif

#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#if HAS_WARNING("-Wmaybe-uninitialized")
#pragma GCC diagnostic warning "-Wmaybe-uninitialized"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
#pragma GCC diagnostic warning "-Warray-bounds"
#pragma GCC diagnostic ignored "-Warray-bounds"

Expand Down
3 changes: 2 additions & 1 deletion util/inc/WireCellUtil/NaryTreeFacade.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ namespace WireCell::NaryTree {

Faced() = default;
Faced(Faced&& other) = default;

Faced& operator=(Faced&& other) = default;

virtual ~Faced() {}

/// Access the facade as type. May return nullptr. Ownership is
Expand Down
21 changes: 21 additions & 0 deletions util/inc/WireCellUtil/Rectangles.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,28 @@
#define WIRECELL_UTIL_RECTANGLES

#include "WireCellUtil/Binning.h"

#if defined __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#endif

#if defined __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-local-typedefs"
#endif

#include "boost/icl/interval_map.hpp"

#if defined __GNUC__
#pragma GCC diagnostic pop
#endif

#if defined __clang__
#pragma clang diagnostic pop
#endif

#include <vector>
#include <set>

namespace WireCell {
Expand Down
4 changes: 3 additions & 1 deletion util/test/test_cnpy_eigen.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "WireCellUtil/Eigen.h"

#include <cassert>

using ntype = short;

// default Eigen ordering
Expand Down Expand Up @@ -68,7 +70,7 @@ int main(int argc, char* argv[])
ArrayXXsColM eig2 = eig;
for (int irow = 0; irow < Nrows; ++irow) {
for (int icol=0; icol < Ncols; ++icol) {
ntype val = icol + irow*Ncols;
ntype val [[maybe_unused]] = icol + irow*Ncols;
assert(eig(irow, icol) == val);
assert(eig2(irow, icol) == val);
}
Expand Down
Loading

0 comments on commit fa806da

Please sign in to comment.