Introduce a serialize/deserialize interface
This commit is contained in:
60
src/libdramsys/DRAMSys/common/Deserialize.h
Normal file
60
src/libdramsys/DRAMSys/common/Deserialize.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2023, RPTU Kaiserslautern-Landau
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Author:
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef DEDESERIALIZE_H
|
||||
#define DEDESERIALIZE_H
|
||||
|
||||
#include <istream>
|
||||
|
||||
namespace DRAMSys
|
||||
{
|
||||
class Deserialize
|
||||
{
|
||||
protected:
|
||||
Deserialize() = default;
|
||||
Deserialize(const Deserialize&) = default;
|
||||
Deserialize(Deserialize&&) = default;
|
||||
Deserialize& operator=(const Deserialize&) = default;
|
||||
Deserialize& operator=(Deserialize&&) = default;
|
||||
|
||||
public:
|
||||
virtual ~Deserialize() = default;
|
||||
|
||||
virtual void deserialize(std::istream& stream) = 0;
|
||||
};
|
||||
|
||||
} // namespace DRAMSys
|
||||
|
||||
#endif
|
||||
60
src/libdramsys/DRAMSys/common/Serialize.h
Normal file
60
src/libdramsys/DRAMSys/common/Serialize.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2023, RPTU Kaiserslautern-Landau
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
|
||||
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* Author:
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef SERIALIZE_H
|
||||
#define SERIALIZE_H
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace DRAMSys
|
||||
{
|
||||
class Serialize
|
||||
{
|
||||
protected:
|
||||
Serialize() = default;
|
||||
Serialize(const Serialize&) = default;
|
||||
Serialize(Serialize&&) = default;
|
||||
Serialize& operator=(const Serialize&) = default;
|
||||
Serialize& operator=(Serialize&&) = default;
|
||||
|
||||
public:
|
||||
virtual ~Serialize() = default;
|
||||
|
||||
virtual void serialize(std::ostream& stream) const = 0;
|
||||
};
|
||||
|
||||
} // namespace DRAMSys
|
||||
|
||||
#endif
|
||||
@@ -71,10 +71,10 @@ Dram::Dram(const sc_module_name& name, const Configuration& config) :
|
||||
memSpec(*config.memSpec),
|
||||
storeMode(config.storeMode),
|
||||
powerAnalysis(config.powerAnalysis),
|
||||
channelSize(memSpec.getSimMemSizeInBytes() / memSpec.numberOfChannels),
|
||||
useMalloc(config.useMalloc),
|
||||
tSocket("socket")
|
||||
{
|
||||
uint64_t channelSize = memSpec.getSimMemSizeInBytes() / memSpec.numberOfChannels;
|
||||
if (storeMode == Configuration::StoreMode::Store)
|
||||
{
|
||||
if (useMalloc)
|
||||
@@ -319,6 +319,18 @@ void Dram::b_transport(tlm_generic_payload& trans, [[maybe_unused]] sc_time& del
|
||||
{
|
||||
SC_REPORT_FATAL("DRAM", "Blocking transport not supported with error model yet.");
|
||||
}
|
||||
|
||||
trans.set_response_status(tlm::TLM_OK_RESPONSE);
|
||||
}
|
||||
|
||||
void Dram::serialize(std::ostream& stream) const
|
||||
{
|
||||
stream.write(reinterpret_cast<char const*>(memory), channelSize);
|
||||
}
|
||||
|
||||
void Dram::deserialize(std::istream& stream)
|
||||
{
|
||||
stream.read(reinterpret_cast<char*>(memory), channelSize);
|
||||
}
|
||||
|
||||
} // namespace DRAMSys
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
#ifndef DRAM_H
|
||||
#define DRAM_H
|
||||
|
||||
#include "DRAMSys/common/Deserialize.h"
|
||||
#include "DRAMSys/common/Serialize.h"
|
||||
#include "DRAMSys/configuration/Configuration.h"
|
||||
#include "DRAMSys/configuration/memspec/MemSpec.h"
|
||||
|
||||
@@ -54,7 +56,7 @@ class libDRAMPower;
|
||||
namespace DRAMSys
|
||||
{
|
||||
|
||||
class Dram : public sc_core::sc_module
|
||||
class Dram : public sc_core::sc_module, public Serialize, public Deserialize
|
||||
{
|
||||
protected:
|
||||
Dram(const sc_core::sc_module_name& name, const Configuration& config);
|
||||
@@ -66,6 +68,7 @@ protected:
|
||||
const Configuration::StoreMode storeMode;
|
||||
const bool powerAnalysis;
|
||||
unsigned char* memory;
|
||||
const uint64_t channelSize;
|
||||
const bool useMalloc;
|
||||
|
||||
#ifdef DRAMPOWER
|
||||
@@ -87,6 +90,9 @@ public:
|
||||
|
||||
virtual void reportPower();
|
||||
|
||||
void serialize(std::ostream& stream) const override;
|
||||
void deserialize(std::istream& stream) override;
|
||||
|
||||
Dram(const Dram&) = delete;
|
||||
Dram(Dram&&) = delete;
|
||||
Dram& operator=(const Dram&) = delete;
|
||||
|
||||
Reference in New Issue
Block a user