Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Pencilcaseman committed Nov 10, 2023
1 parent ae1dd3a commit 222dd32
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
41 changes: 41 additions & 0 deletions librapid/bindings/generators/arrayGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,47 @@ def generateFunctionsForArray(config):
)
)

if config["backend"] == "CPU":
functions += [
function.Function(
name=f"serialize{config['name']}",
args=[
argument.Argument(
name="array",
type=generateCppArrayType(config),
const=True,
ref=True
),
argument.Argument(
name="path",
type="std::string",
const=True,
ref=True
)
],
op="""
return lrc::serialize::Serializer(array).write(path);
"""
),

function.Function(
name=f"deserialize{config['name']}",
args=[
argument.Argument(
name="path",
type="std::string",
const=True,
ref=True
)
],
op=f"""
lrc::serialize::Serializer<{generateCppArrayType(config)}> serializer;
serializer.read(path);
return serializer.deserialize();
"""
)
]

return methods, functions


Expand Down
20 changes: 12 additions & 8 deletions librapid/bindings/generators/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,23 @@
#endif
module.def("hasOpenCL", []() {{
#if defined(LIBRAPID_HAS_OPENCL)
return true;
#else
// #if defined(LIBRAPID_HAS_OPENCL)
// return true;
// #else
// return false;
// #endif
return false;
#endif
}});
module.def("hasCUDA", []() {{
#if defined(LIBRAPID_HAS_CUDA)
return true;
#else
// #if defined(LIBRAPID_HAS_CUDA)
// return true;
// #else
// return false;
// #endif
return false;
#endif
}});
module.def("setNumThreads", [](size_t numThreads) {{
Expand Down
9 changes: 7 additions & 2 deletions librapid/include/librapid/utils/serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ namespace librapid::serialize {

LIBRAPID_NODISCARD bool write(const std::string &path) const {
std::fstream file(path, std::ios::out | detail::fileBinMode(path));
return write(file);
bool ret = write(file);
file.close();
return ret;
}

LIBRAPID_NODISCARD bool read(std::fstream &file) {
file.seekg(0, std::ios::end);
if (file.tellg() == -1) return false;
m_data.resize(file.tellg());
file.seekg(0, std::ios::beg);
file.read(reinterpret_cast<char *>(m_data.data()), m_data.size());
Expand All @@ -86,7 +89,9 @@ namespace librapid::serialize {

LIBRAPID_NODISCARD bool read(const std::string &path) {
std::fstream f(path, std::ios::in | detail::fileBinMode(path));
return read(f);
bool ret = read(f);
f.close();
return ret;
}

private:
Expand Down

0 comments on commit 222dd32

Please sign in to comment.