"src/array/vscode:/vscode.git/clone" did not exist on "3e72c53ae0ecd16ae057aa63e81f0c57f5828fa8"
python_binding.cc 4.08 KB
Newer Older
sangwzh's avatar
sangwzh committed
1
// !!! This is a file automatically generated by hipify!!!
2
3
4
5
6
7
/**
 *  Copyright (c) 2023 by Contributors
 * @file python_binding.cc
 * @brief Graph bolt library Python binding.
 */

8
#include <graphbolt/fused_csc_sampling_graph.h>
9
#include <graphbolt/isin.h>
10
#include <graphbolt/serialize.h>
11
#include <graphbolt/unique_and_compact.h>
12

13
#ifdef GRAPHBOLT_USE_CUDA
sangwzh's avatar
sangwzh committed
14
#include "cuda/max_uva_threads.h"
15
#endif
sangwzh's avatar
sangwzh committed
16
17
18
#include "expand_indptr.h"
#include "index_select.h"
#include "random.h"
19

20
#ifdef GRAPHBOLT_USE_CUDA
sangwzh's avatar
sangwzh committed
21
#include "cuda/gpu_cache.h"
22
23
#endif

24
25
26
27
namespace graphbolt {
namespace sampling {

TORCH_LIBRARY(graphbolt, m) {
28
  m.class_<FusedSampledSubgraph>("FusedSampledSubgraph")
29
      .def(torch::init<>())
30
31
      .def_readwrite("indptr", &FusedSampledSubgraph::indptr)
      .def_readwrite("indices", &FusedSampledSubgraph::indices)
32
      .def_readwrite(
33
          "original_row_node_ids", &FusedSampledSubgraph::original_row_node_ids)
34
      .def_readwrite(
35
          "original_column_node_ids",
36
37
38
39
          &FusedSampledSubgraph::original_column_node_ids)
      .def_readwrite(
          "original_edge_ids", &FusedSampledSubgraph::original_edge_ids)
      .def_readwrite("type_per_edge", &FusedSampledSubgraph::type_per_edge);
40
41
42
43
44
45
46
  m.class_<FusedCSCSamplingGraph>("FusedCSCSamplingGraph")
      .def("num_nodes", &FusedCSCSamplingGraph::NumNodes)
      .def("num_edges", &FusedCSCSamplingGraph::NumEdges)
      .def("csc_indptr", &FusedCSCSamplingGraph::CSCIndptr)
      .def("indices", &FusedCSCSamplingGraph::Indices)
      .def("node_type_offset", &FusedCSCSamplingGraph::NodeTypeOffset)
      .def("type_per_edge", &FusedCSCSamplingGraph::TypePerEdge)
47
48
      .def("node_type_to_id", &FusedCSCSamplingGraph::NodeTypeToID)
      .def("edge_type_to_id", &FusedCSCSamplingGraph::EdgeTypeToID)
49
      .def("node_attributes", &FusedCSCSamplingGraph::NodeAttributes)
50
51
52
53
54
      .def("edge_attributes", &FusedCSCSamplingGraph::EdgeAttributes)
      .def("set_csc_indptr", &FusedCSCSamplingGraph::SetCSCIndptr)
      .def("set_indices", &FusedCSCSamplingGraph::SetIndices)
      .def("set_node_type_offset", &FusedCSCSamplingGraph::SetNodeTypeOffset)
      .def("set_type_per_edge", &FusedCSCSamplingGraph::SetTypePerEdge)
55
56
      .def("set_node_type_to_id", &FusedCSCSamplingGraph::SetNodeTypeToID)
      .def("set_edge_type_to_id", &FusedCSCSamplingGraph::SetEdgeTypeToID)
57
      .def("set_node_attributes", &FusedCSCSamplingGraph::SetNodeAttributes)
58
59
60
      .def("set_edge_attributes", &FusedCSCSamplingGraph::SetEdgeAttributes)
      .def("in_subgraph", &FusedCSCSamplingGraph::InSubgraph)
      .def("sample_neighbors", &FusedCSCSamplingGraph::SampleNeighbors)
61
62
63
      .def(
          "temporal_sample_neighbors",
          &FusedCSCSamplingGraph::TemporalSampleNeighbors)
64
      .def("copy_to_shared_memory", &FusedCSCSamplingGraph::CopyToSharedMemory)
65
66
      .def_pickle(
          // __getstate__
67
          [](const c10::intrusive_ptr<FusedCSCSamplingGraph>& self)
68
69
70
71
72
73
              -> torch::Dict<
                  std::string, torch::Dict<std::string, torch::Tensor>> {
            return self->GetState();
          },
          // __setstate__
          [](torch::Dict<std::string, torch::Dict<std::string, torch::Tensor>>
74
75
                 state) -> c10::intrusive_ptr<FusedCSCSamplingGraph> {
            auto g = c10::make_intrusive<FusedCSCSamplingGraph>();
76
77
78
            g->SetState(state);
            return g;
          });
79
80
81
82
83
84
#ifdef GRAPHBOLT_USE_CUDA
  m.class_<cuda::GpuCache>("GpuCache")
      .def("query", &cuda::GpuCache::Query)
      .def("replace", &cuda::GpuCache::Replace);
  m.def("gpu_cache", &cuda::GpuCache::Create);
#endif
85
  m.def("fused_csc_sampling_graph", &FusedCSCSamplingGraph::Create);
86
87
  m.def(
      "load_from_shared_memory", &FusedCSCSamplingGraph::LoadFromSharedMemory);
88
  m.def("unique_and_compact", &UniqueAndCompact);
89
  m.def("isin", &IsIn);
90
  m.def("index_select", &ops::IndexSelect);
91
  m.def("index_select_csc", &ops::IndexSelectCSC);
92
  m.def("expand_indptr", &ops::ExpandIndptr);
93
  m.def("set_seed", &RandomEngine::SetManualSeed);
94
95
96
#ifdef GRAPHBOLT_USE_CUDA
  m.def("set_max_uva_threads", &cuda::set_max_uva_threads);
#endif
97
98
99
100
}

}  // namespace sampling
}  // namespace graphbolt