MCPcopy Create free account
hub / github.com/DeepGraphLearning/graphvite / SamplerMixin

Class SamplerMixin

include/core/solver.h:904–1146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

902 */
903template<class _Solver, class ..._Attributes>
904class SamplerMixin {
905public:
906 typedef _Solver Solver;
907 typedef typename Solver::Float Float;
908 typedef typename Solver::Index Index;
909
910 typedef std::tuple<_Attributes...> Attributes;
911 typedef std::tuple<Index, Index, _Attributes...> EdgeSample;
912 typedef typename Solver::Graph::Edge Edge;
913
914 static const int kSampleSize = sizeof(EdgeSample) / sizeof(Index);
915 static_assert(sizeof(EdgeSample) % sizeof(Index) == 0, "sizeof(EdgeSample) must be a multiplier of sizeof(Index)");
916
917 Solver *solver;
918 int device_id;
919 cudaStream_t stream;
920 Memory<double, int> random;
921 curandGenerator_t generator;
922 int num_partition, pool_size;
923
924#define USING_SAMPLER_MIXIN(type) \
925 using typename type::Solver; \
926 using typename type::Float; \
927 using typename type::Index; \
928 using typename type::Attributes; \
929 using typename type::Edge; \
930 using type::solver; \
931 using type::device_id; \
932 using type::stream; \
933 using type::random; \
934 using type::generator; \
935 using type::num_partition; \
936 using type::pool_size
937
938 /**
939 * Construct a general edge sampler
940 * @param _solver pointer to graph embedding solver
941 * @param _device_id GPU id
942 */
943 SamplerMixin(Solver *_solver, int _device_id) :
944 solver(_solver), device_id(_device_id), random(device_id) {
945 CUDA_CHECK(cudaSetDevice(device_id));
946
947 CUDA_CHECK(cudaStreamCreate(&stream));
948
949 random.stream = stream;
950 CURAND_CHECK(curandCreateGenerator(&generator, CURAND_RNG_PSEUDO_DEFAULT));
951 std::uniform_int_distribution<unsigned long long> random_seed(0, ULLONG_MAX);
952 CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(generator, random_seed(seed)));
953 CURAND_CHECK(curandSetStream(generator, stream));
954 }
955
956 /** Should return the additional attributes */
957 virtual Attributes get_attributes(const Edge &edge) const = 0;
958
959 /** Determine and allocate all resources for the sampler */
960 void build() {
961 CUDA_CHECK(cudaSetDevice(device_id));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected