Skip to content

Commit a6ca6e6

Browse files
committed
Move template specialization to the OpenCL backend.
The presence of the template specialization in af/opencl.h results in multiple definitions of af::array::device<cl_mem>() if the header is included in more than one source file. The proposed commit simply moves the definition into a source file in the backend. Fixes issue #1429
1 parent 7039b89 commit a6ca6e6

2 files changed

Lines changed: 12 additions & 22 deletions

File tree

‎include/af/opencl.h‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -434,27 +434,5 @@ static inline platform getPlatform()
434434
*/
435435
}
436436

437-
namespace af
438-
{
439-
/**
440-
\addtogroup opencl_mat
441-
@{
442-
*/
443-
444-
#if !defined(AF_OPENCL)
445-
template<> AFAPI cl_mem *array::device() const
446-
{
447-
cl_mem *mem_ptr = new cl_mem;
448-
af_err err = af_get_device_ptr((void **)mem_ptr, get());
449-
if (err != AF_SUCCESS) throw af::exception("Failed to get cl_mem from array object");
450-
return mem_ptr;
451-
}
452-
#endif
453-
454-
/**
455-
@}
456-
*/
457-
458-
}
459437

460438
#endif

‎src/backend/opencl/api.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <af/array.h>
2+
#include <af/opencl.h>
3+
4+
namespace af {
5+
template<> AFAPI cl_mem *array::device() const
6+
{
7+
cl_mem *mem_ptr = new cl_mem;
8+
af_err err = af_get_device_ptr((void **)mem_ptr, get());
9+
if (err != AF_SUCCESS) throw af::exception("Failed to get cl_mem from array object");
10+
return mem_ptr;
11+
}
12+
}

0 commit comments

Comments
 (0)