Skip to content

Commit

Permalink
Adding API functions to convert data buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsala committed Jun 15, 2021
1 parent b9a8714 commit 75bd972
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pkginclude_HEADERS= # This library does not provide any additional header

c_api_sources= \
src/c/CBLASOperations.cpp \
src/c/Converters.cpp \
src/c/Initialization.cpp \
src/c/MemoryOperations.cpp \
src/c/Operations.cpp \
Expand Down
82 changes: 82 additions & 0 deletions src/c/Converters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
This file is part of Task-Aware ACL and is licensed under the terms contained in the COPYING and COPYING.LESSER files.
Copyright (C) 2021 Barcelona Supercomputing Center (BSC)
*/

#include <acl/acl.h>
#include <TACL.h>

#include <cassert>

#pragma GCC visibility push(default)

extern "C" {

aclError
taclDoubleToFloat16Buffer(aclFloat16 *dst, const double *src, size_t count)
{
if (count == 0)
return ACL_ERROR_NONE;

assert(dst != NULL);
assert(src != NULL);

for (size_t e = 0; e < count; ++e) {
dst[e] = aclFloatToFloat16((float) src[e]);
}

return ACL_ERROR_NONE;
}

aclError
taclFloatToFloat16Buffer(aclFloat16 *dst, const float *src, size_t count)
{
if (count == 0)
return ACL_ERROR_NONE;

assert(dst != NULL);
assert(src != NULL);

for (size_t e = 0; e < count; ++e) {
dst[e] = aclFloatToFloat16(src[e]);
}

return ACL_ERROR_NONE;
}

aclError
taclFloat16ToDoubleBuffer(double *dst, const aclFloat16 *src, size_t count)
{
if (count == 0)
return ACL_ERROR_NONE;

assert(dst != NULL);
assert(src != NULL);

for (size_t e = 0; e < count; ++e) {
dst[e] = (double) aclFloat16ToFloat(src[e]);
}

return ACL_ERROR_NONE;
}

aclError
taclFloat16ToFloatBuffer(float *dst, const aclFloat16 *src, size_t count)
{
if (count == 0)
return ACL_ERROR_NONE;

assert(dst != NULL);
assert(src != NULL);

for (size_t e = 0; e < count; ++e) {
dst[e] = aclFloat16ToFloat(src[e]);
}

return ACL_ERROR_NONE;
}

} // extern C

#pragma GCC visibility pop
12 changes: 12 additions & 0 deletions src/include/TACL.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ taclWaitRequestAsync(taclRequest *request);
aclError
taclWaitallRequestsAsync(size_t count, taclRequest requests[]);

aclError
taclDoubleToFloat16Buffer(aclFloat16 *dst, const double *src, size_t count);

aclError
taclFloatToFloat16Buffer(aclFloat16 *dst, const float *src, size_t count);

aclError
taclFloat16ToDoubleBuffer(double *dst, const aclFloat16 *src, size_t count);

aclError
taclFloat16ToFloatBuffer(float *dst, const aclFloat16 *src, size_t count);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 75bd972

Please sign in to comment.