Skip to content

Instantly share code, notes, and snippets.

# Cereal Serialization Library
FIND_PACKAGE(Cereal)
IF(NOT CEREAL_FOUND)
include(external/Cereal)
LIST(APPEND INCLUDES ${CEREAL_INCLUDE_DIR})
ELSE()
LIST(APPEND INCLUDES ${CEREAL_INCLUDE_DIR})
ENDIF()
#include <shogun/lib/config.h>
#include <shogun/lib/SGVector.h>
#include <memory>
#include <shogun/mathematics/eigen3.h>
class linalg_new
{
shared_ptr<CPUBackend> cpu_backend;
shared_ptr<GPUBackend> gpu_backend;
namespace linalg
{
    // Always return CPU T type
    template<class T>
    T dot(SGVector<T> a, SGVector<T> b)
    {
        Base<T> base_a = factory(a); // Factory: use ifdef to check if GPUbackend exists and GPU is turned on
        Base<T> base_b = factory(b);
        return base_a.dot(base_b)
    }

Goal

Replace current Shogun serialization method with Cereal libarary

Include Cereal library

Cereal library is a header only library so no build or make is required. However, Shogun needs to make sure Cereal library is ready for use.

Thus, CMakeList needs to check and download Cereal if necessary:

IF (Cereal)
@OXPHOS
OXPHOS / cereal_test.cpp
Created May 15, 2016 04:43
Serialization
#include <cereal/types/unordered_map.hpp>
#include <cereal/types/memory.hpp>
#include <cereal/archives/json.hpp>
#include <fstream>
struct MyRecord
{
uint8_t x = 10, y = 100;
float z = 3.2;
template<class T> class SGVector : public SGReferencedData
{
// If have ViennaCL: declare a pointer to GPU memory
// So only one GPU object is created for one SGVector
#ifdef HAVE_VIENNACL
typedef viennacl::backend::mem_handle VCLMemoryArray;
public:
shared_pointer<VCLMemoryArray> GPUptr(nullptr);
bool on_GPU():