Skip to content

Commit

Permalink
Merge pull request oneapi-src#1 from averbukh/subgraph_iso
Browse files Browse the repository at this point in the history
Non-induced case modifications
  • Loading branch information
orazve committed Apr 8, 2021
2 parents 8afa111 + 9dddc11 commit ea9f42b
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ graph_matching_result call_subgraph_isomorphism_default_kernel(
}

std::uint64_t control_flags = flow_switch_ids::multi_thread_mode;
solution results = si(pattern, target, control_flags);
solution results = si(pattern, target, desc.get_kind(), control_flags);

if (t_vertex_attribute)
dal::preview::detail::deallocate(int64_allocator, t_vertex_attribute, t_vertex_count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ struct graph_matching_ops {
void check_preconditions(const Descriptor &param, graph_matching_input<Graph> &input) const {
using msg = dal::detail::error_messages;

if (param.get_kind() != kind::induced) {
throw invalid_argument(msg::unsupported_kind());
}
if (param.get_max_match_count() < 0) {
throw invalid_argument(msg::max_match_count_lt_zero());
}
Expand Down
39 changes: 25 additions & 14 deletions cpp/oneapi/dal/algo/subgraph_isomorphism/detail/matching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ matching_engine::matching_engine(const graph* ppattern,
const std::int64_t* psorted_pattern_vertex,
const std::int64_t* ppredecessor,
const edge_direction* pdirection,
sconsistent_conditions const* pcconditions) {
sconsistent_conditions const* pcconditions,
kind isomorphism_kind)
: isomorphism_kind_(isomorphism_kind) {
pattern = ppattern;
target = ptarget;
sorted_pattern_vertex = psorted_pattern_vertex;
Expand Down Expand Up @@ -66,19 +68,23 @@ matching_engine::matching_engine(const matching_engine& _matching_engine, stack&
_matching_engine.sorted_pattern_vertex,
_matching_engine.predecessor,
_matching_engine.direction,
_matching_engine.pconsistent_conditions) {
_matching_engine.pconsistent_conditions,
_matching_engine.isomorphism_kind_) {
local_stack = std::move(_local_stack);
}

std::int64_t matching_engine::state_exploration_bit(state* current_state, bool check_solution) {
const std::int64_t i_cc = current_state->core_length - 1;
const std::int64_t divider = pconsistent_conditions[i_cc].divider;

if (isomorphism_kind_ != kind::non_induced) {
#pragma ivdep
for (std::int64_t j = 0; j < divider; j++) {
or_equal(vertex_candidates.get_vector_pointer(),
target->p_edges_bit[current_state->core[pconsistent_conditions[i_cc].array[j]]],
vertex_candidates.size());
for (std::int64_t j = 0; j < divider; j++) {
or_equal(
vertex_candidates.get_vector_pointer(),
target->p_edges_bit[current_state->core[pconsistent_conditions[i_cc].array[j]]],
vertex_candidates.size());
}
}

~vertex_candidates; // inversion?
Expand All @@ -101,12 +107,14 @@ std::int64_t matching_engine::state_exploration_bit(bool check_solution) {
std::uint64_t current_level_index = hlocal_stack.get_current_level_index();
std::int64_t divider = pconsistent_conditions[current_level_index].divider;

if (isomorphism_kind_ != kind::non_induced) {
#pragma ivdep
for (std::int64_t j = 0; j < divider; j++) {
or_equal(vertex_candidates.get_vector_pointer(),
target->p_edges_bit[hlocal_stack.top(
pconsistent_conditions[current_level_index].array[j])],
vertex_candidates.size());
for (std::int64_t j = 0; j < divider; j++) {
or_equal(vertex_candidates.get_vector_pointer(),
target->p_edges_bit[hlocal_stack.top(
pconsistent_conditions[current_level_index].array[j])],
vertex_candidates.size());
}
}

~vertex_candidates; // inversion ?
Expand Down Expand Up @@ -379,7 +387,9 @@ engine_bundle::engine_bundle(const graph* ppattern,
const edge_direction* pdirection,
sconsistent_conditions const* pcconditions,
float* ppattern_vertex_probability,
const std::uint64_t _control_flags) {
const std::uint64_t _control_flags,
kind isomorphism_kind)
: isomorphism_kind_(isomorphism_kind) {
pattern = ppattern;
target = ptarget;
sorted_pattern_vertex = psorted_pattern_vertex;
Expand Down Expand Up @@ -426,7 +436,8 @@ solution engine_bundle::run() {
sorted_pattern_vertex,
predecessor,
direction,
pconsistent_conditions);
pconsistent_conditions,
isomorphism_kind_);
}

state null_state;
Expand Down Expand Up @@ -486,4 +497,4 @@ void engine_bundle::first_states_generator(bool use_exploration_stack) {
});
}
}
} // namespace oneapi::dal::preview::subgraph_isomorphism::detail
} // namespace oneapi::dal::preview::subgraph_isomorphism::detail
12 changes: 9 additions & 3 deletions cpp/oneapi/dal/algo/subgraph_isomorphism/detail/matching.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "oneapi/dal/algo/subgraph_isomorphism/detail/solution.hpp"
#include "oneapi/dal/algo/subgraph_isomorphism/detail/stack.hpp"
#include "oneapi/dal/detail/threading.hpp"
#include "oneapi/dal/algo/subgraph_isomorphism/common.hpp"

namespace oneapi::dal::preview::subgraph_isomorphism::detail {

Expand All @@ -23,7 +24,8 @@ class matching_engine {
const std::int64_t* psorted_pattern_vertex,
const std::int64_t* ppredecessor,
const edge_direction* pdirection,
sconsistent_conditions const* pcconditions);
sconsistent_conditions const* pcconditions,
kind isomorphism_kind);
matching_engine(const matching_engine& _matching_engine, stack& _local_stack);
virtual ~matching_engine();

Expand Down Expand Up @@ -67,6 +69,8 @@ class matching_engine {
dfs_stack hlocal_stack;
solution engine_solutions;

kind isomorphism_kind_;

std::int64_t extract_candidates(state* current_state, bool check_solution);
bool check_vertex_candidate(state* current_state, bool check_solution);

Expand All @@ -86,7 +90,8 @@ class engine_bundle {
const edge_direction* pdirection,
sconsistent_conditions const* pcconditions,
float* ppattern_vertex_probability,
const std::uint64_t _control_flags);
const std::uint64_t _control_flags,
kind isomorphism_kind);
virtual ~engine_bundle();
solution run();

Expand All @@ -99,11 +104,12 @@ class engine_bundle {
const sconsistent_conditions* pconsistent_conditions;
const float* pattern_vertex_probability;
std::uint64_t control_flags;
kind isomorphism_kind_;

solution bundle_solutions;

typedef oneapi::dal::detail::tls_mem<matching_engine, std::allocator<double>> bundle;
bundle matching_bundle;
void first_states_generator(bool use_exploration_stack = true);
};
} // namespace oneapi::dal::preview::subgraph_isomorphism::detail
} // namespace oneapi::dal::preview::subgraph_isomorphism::detail
9 changes: 7 additions & 2 deletions cpp/oneapi/dal/algo/subgraph_isomorphism/detail/si.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "oneapi/dal/algo/subgraph_isomorphism/detail/solution.hpp"
#include "oneapi/dal/algo/subgraph_isomorphism/detail/sorter.hpp"
#include "oneapi/dal/algo/subgraph_isomorphism/detail/matching.hpp"
#include "oneapi/dal/algo/subgraph_isomorphism/common.hpp"

namespace oneapi::dal::preview::subgraph_isomorphism::detail {

Expand All @@ -13,7 +14,10 @@ std::shared_ptr<T> make_shared_malloc(std::uint64_t elements_count) {
return std::shared_ptr<T>(ptr, _mm_free);
}

solution si(const graph& pattern, const graph& target, const std::uint64_t control_flags = 0) {
solution si(const graph& pattern,
const graph& target,
kind isomorphism_kind,
const std::uint64_t control_flags = 0) {
solution sol;
sorter sorter_graph(&target);
std::int64_t pattern_vetrex_count = pattern.get_vertex_count();
Expand Down Expand Up @@ -57,7 +61,8 @@ solution si(const graph& pattern, const graph& target, const std::uint64_t contr
direction.get(),
cconditions.get(),
pattern_vertex_probability.get(),
control_flags);
control_flags,
isomorphism_kind);
sol = harness.run();

for (std::int64_t i = 0; i < (pattern_vetrex_count - 1); i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "oneapi/dal/algo/subgraph_isomorphism/detail/solution.hpp"
#include <cassert>

namespace dal = oneapi::dal;
namespace oneapi::dal::preview::subgraph_isomorphism::detail {
Expand Down
1 change: 0 additions & 1 deletion cpp/oneapi/dal/detail/error_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ MSG(row_begin_gt_row_end, "Row begin is greater than row end")
MSG(range_idx_gt_max_int32, "Range indexes are greater than max of int32")

/* Subgraph Isomorphism */
MSG(unsupported_kind, "Unsupported kind of subgraph")
MSG(max_match_count_lt_zero, "Maximum number of match count less that zero")
MSG(unsupported_semantic_match, "Unsupported semantic match mode")

Expand Down
16 changes: 16 additions & 0 deletions examples/oneapi/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ dal_module(
name = "example_util",
hdrs = glob(["source/example_util/*.hpp"]),
includes = [ "source" ],
dal_deps = [
"@onedal//cpp/oneapi/dal/algo:jaccard",
],
)

_TEST_DEPS = [
Expand Down Expand Up @@ -65,6 +68,19 @@ dal_example_suite(
],
)

dal_example_suite(
name = "subgraph_isomorphism",
compile_as = [ "c++" ],
srcs = glob(["source/subgraph_isomorphism/*.cpp"]),
dal_deps = [
"@onedal//cpp/oneapi/dal/algo:subgraph_isomorphism",
],
data = _DATA_DEPS,
extra_deps = _TEST_DEPS + [
"@tbb//:tbb",
],
)

dal_algo_example_suite(
algos = [
"decision_forest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ int main(int argc, char **argv) {
// "/export/users/orazvens/si-non-induced/subgraph-isomorphism-prototype/data/PDBSv1/singles/103l.pdb.gff_queries/query32_1.gff");

auto target_filename = get_data_path(
"/export/users/orazvens/si-non-induced/subgraph-isomorphism-prototype/data/PDBSv1/singles/103l.pdb.gff");
"/nfs/inn/disks/nn-ssg_spd_numerics_users/maverbuk/daal_branches/si-proto/data/PDBSv1/singles/103l.pdb.gff");
auto pattern_filename = get_data_path(
"/export/users/orazvens/si-non-induced/subgraph-isomorphism-prototype/data/PDBSv1/singles/103l.pdb.gff_queries/query4_0.gff");
"/nfs/inn/disks/nn-ssg_spd_numerics_users/maverbuk/daal_branches/si-proto/data/PDBSv1/singles/103l.pdb.gff_queries/query32_1.gff");

// 1240 1237 1241 1242 1243
// 1240 1237 1241 1243 1242
Expand All @@ -143,7 +143,7 @@ int main(int argc, char **argv) {
// set algorithm parameters
const auto subgraph_isomorphism_desc =
dal::preview::subgraph_isomorphism::descriptor<>(alloc)
.set_kind(dal::preview::subgraph_isomorphism::kind::induced)
.set_kind(dal::preview::subgraph_isomorphism::kind::non_induced)
.set_semantic_match(false)
.set_max_match_count(100);

Expand Down

0 comments on commit ea9f42b

Please sign in to comment.