Commit d57cba45 authored by Armin Sobhani's avatar Armin Sobhani
Browse files

add support for making boost.compute test to cmake

parent c6ca8862
......@@ -11,6 +11,10 @@ cmake_minimum_required(VERSION 2.8)
project(BoostBioseq)
# find OpenCL
find_package(OpenCL REQUIRED)
include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
# find Boost
find_package(Boost 1.53 REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
......
# - Try to find OpenCL
# This module tries to find an OpenCL implementation on your system. It supports
# AMD / ATI, Apple and NVIDIA implementations.
#
# To set the paths manually, define these environment variables:
# OpenCL_INCPATH - Include path (e.g. OpenCL_INCPATH=/opt/cuda/4.0/cuda/include)
# OpenCL_LIBPATH - Library path (e.h. OpenCL_LIBPATH=/usr/lib64/nvidia)
#
# Once done this will define
# OpenCL_FOUND - system has OpenCL
# OpenCL_INCLUDE_DIRS - the OpenCL include directory
# OpenCL_LIBRARIES - link these to use OpenCL
FIND_PACKAGE(PackageHandleStandardArgs)
SET (OpenCL_VERSION_STRING "0.1.0")
SET (OpenCL_VERSION_MAJOR 0)
SET (OpenCL_VERSION_MINOR 1)
SET (OpenCL_VERSION_PATCH 0)
IF (APPLE)
FIND_LIBRARY(OpenCL_LIBRARIES OpenCL DOC "OpenCL lib for OSX")
FIND_PATH(OpenCL_INCLUDE_DIRS OpenCL/cl.h DOC "Include for OpenCL on OSX")
FIND_PATH(_OpenCL_CPP_INCLUDE_DIRS OpenCL/cl.hpp DOC "Include for OpenCL CPP bindings on OSX")
ELSE (APPLE)
IF (WIN32)
# The AMD SDK currently installs both x86 and x86_64 libraries
# This is only a hack to find out architecture
IF( CMAKE_SIZEOF_VOID_P EQUAL 8 )
SET(OpenCL_LIB_DIR "$ENV{AMDAPPSDKROOT}/lib/x86_64")
ELSE( CMAKE_SIZEOF_VOID_P EQUAL 8 )
SET(OpenCL_LIB_DIR "$ENV{AMDAPPSDKROOT}/lib/x86")
ENDIF( CMAKE_SIZEOF_VOID_P EQUAL 8 )
FIND_LIBRARY(OpenCL_LIBRARIES OpenCL.lib PATHS
${OpenCL_LIB_DIR} $ENV{OpenCL_LIBPATH} $ENV{CUDA_LIB_PATH})
GET_FILENAME_COMPONENT(_OpenCL_INC_CAND ${OpenCL_LIB_DIR}/../../include ABSOLUTE)
# On Win32 search relative to the library
FIND_PATH(OpenCL_INCLUDE_DIRS CL/cl.h PATHS
${_OpenCL_INC_CAND} $ENV{OpenCL_INCPATH} $ENV{CUDA_INC_PATH})
FIND_PATH(_OpenCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS
${_OpenCL_INC_CAND} $ENV{OpenCL_INCPATH} $ENV{CUDA_INC_PATH})
ELSE (WIN32)
# Unix style platforms
FIND_LIBRARY(OpenCL_LIBRARIES OpenCL
PATHS ENV LD_LIBRARY_PATH ENV OpenCL_LIBPATH
)
GET_FILENAME_COMPONENT(OpenCL_LIB_DIR ${OpenCL_LIBRARIES} PATH)
GET_FILENAME_COMPONENT(_OpenCL_INC_CAND ${OpenCL_LIB_DIR}/../../include ABSOLUTE)
# The AMD SDK currently does not place its headers
# in /usr/include, therefore also search relative
# to the library
FIND_PATH(OpenCL_INCLUDE_DIRS CL/cl.h PATHS "$ENV{CUDADIR}/include" ${_OpenCL_INC_CAND} "/usr/local/cuda/include" "/opt/cuda/include" "/opt/AMDAPP/include" ENV OpenCL_INCPATH)
FIND_PATH(_OpenCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS "$ENV{CUDADIR}/include" ${_OpenCL_INC_CAND} "/usr/local/cuda/include" "/opt/cuda/include" "/opt/AMDAPP/include" ENV OpenCL_INCPATH)
# for Mali GPUs, libmali must be linked
FIND_LIBRARY(OpenCL_LIBRARIES_MALI mali
PATHS ENV LD_LIBRARY_PATH ENV OpenCL_LIBPATH "/usr/lib64" "$ENV{CUDADIR}/lib64"
)
IF (OpenCL_LIBRARIES_MALI)
SET(OpenCL_LIBRARIES ${OpenCL_LIBRARIES} ${OpenCL_LIBRARIES_MALI})
ENDIF (OpenCL_LIBRARIES_MALI)
ENDIF (WIN32)
ENDIF (APPLE)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenCL DEFAULT_MSG OpenCL_LIBRARIES OpenCL_INCLUDE_DIRS)
IF(_OpenCL_CPP_INCLUDE_DIRS)
SET( OpenCL_HAS_CPP_BINDINGS TRUE )
LIST( APPEND OpenCL_INCLUDE_DIRS ${_OpenCL_CPP_INCLUDE_DIRS} )
# This is often the same, so clean up
LIST( REMOVE_DUPLICATES OpenCL_INCLUDE_DIRS )
ENDIF(_OpenCL_CPP_INCLUDE_DIRS)
MARK_AS_ADVANCED( OpenCL_INCLUDE_DIRS )
......@@ -45,10 +45,18 @@ public:
: ContainerT<CharT, AllocatorT<CharT>>(alloc)
{}
sequence_host(
const CharT* s
, size_t count)
: ContainerT<CharT, AllocatorT<CharT>>()
{
self_type::insert(self_type::begin(), s, s + count);
}
sequence_host(
const CharT* s
, size_t count
, const AllocatorT<CharT>& alloc = AllocatorT<CharT>() )
, const AllocatorT<CharT>& alloc)
: ContainerT<CharT, AllocatorT<CharT>>(alloc)
{
self_type::insert(self_type::begin(), s, s + count);
......
......@@ -40,6 +40,7 @@ function(add_bioseq_test TEST_NAME TEST_SOURCE)
get_filename_component(TEST_TARGET ${TEST_SOURCE} NAME_WE)
add_executable(${TEST_TARGET} ${TEST_SOURCE})
target_link_libraries(${TEST_TARGET}
${OpenCL_LIBRARIES}
${Boost_LIBRARIES}
)
......@@ -47,6 +48,7 @@ function(add_bioseq_test TEST_NAME TEST_SOURCE)
endfunction()
add_bioseq_test("sequence" test_sequence.cpp)
#add_bioseq_test("boost.compute.sequence" test_bc_sequence.cpp)
add_bioseq_test("name.component" test_name_component.cpp)
add_bioseq_test("description.component" test_description_component.cpp)
add_bioseq_test("io.fasta" test_io_fasta.cpp)
//----------------------------------------------------------------------------//
// Copyright (c) 2018 Armin Sobhani <arminms@gmail.com>
//
// Distributed under the Boost Software License Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
//----------------------------------------------------------------------------//
#define BOOST_TEST_MODULE TestBoostComputeSequence
#include <boost/mpl/list.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/compute/system.hpp>
#include <boost/compute/command_queue.hpp>
#include <boost/compute/container/vector.hpp>
#include <boost/compute/container/basic_string.hpp>
#include <boost/bioseq/type_traits.hpp>
#include <boost/bioseq/sequence.hpp>
namespace bsq = boost::bioseq;
namespace bc = boost::compute;
template<class CharT, class Allocator> using bs_string
= bc::basic_string<CharT, std::char_traits<CharT>>;
typedef bsq::sequence_host<char, std::allocator, bs_string> str_seq;
typedef bsq::sequence_host<char, std::allocator, bc::vector> vec_seq;
// typedef boost::mpl::list<vec_seq> seq_types;
typedef boost::mpl::list<vec_seq, str_seq> seq_types;
struct Context
{
boost::compute::device device;
boost::compute::context context;
boost::compute::command_queue queue;
Context() :
device ( boost::compute::system::default_device() ),
context( boost::compute::system::default_context() ),
queue ( boost::compute::system::default_queue() )
{}
};
BOOST_FIXTURE_TEST_SUITE(compute_test, Context)
BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_char_pointer_n, T, seq_types)
{
T seq("ATCGN", 4);
auto b = seq.cbegin();
BOOST_CHECK_EQUAL( *b , 'A');
BOOST_CHECK_EQUAL(*(++b), 'T');
BOOST_CHECK_EQUAL(*(++b), 'C');
BOOST_CHECK_EQUAL(*(++b), 'G');
BOOST_CHECK_EQUAL(seq.size(), 4);
BOOST_CHECK(++b == seq.end());
}
// BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_char_pointer, T, seq_types)
// {
// T seq("ATCG");
// auto b = seq.cbegin();
// BOOST_CHECK_EQUAL( *b , 'A');
// BOOST_CHECK_EQUAL(*(++b), 'T');
// BOOST_CHECK_EQUAL(*(++b), 'C');
// BOOST_CHECK_EQUAL(*(++b), 'G');
// BOOST_CHECK_EQUAL(seq.size(), 4);
// BOOST_CHECK(++b == seq.end());
// }
// BOOST_AUTO_TEST_CASE_TEMPLATE(copy_constructor, T, seq_types)
// {
// T seq("ATCG");
// T copy(seq);
// BOOST_CHECK_EQUAL(copy.size(), 4);
// auto b = copy.cbegin();
// BOOST_CHECK_EQUAL( *b , 'A');
// BOOST_CHECK_EQUAL(*(++b), 'T');
// BOOST_CHECK_EQUAL(*(++b), 'C');
// BOOST_CHECK_EQUAL(*(++b), 'G');
// }
// BOOST_AUTO_TEST_CASE_TEMPLATE(move_constructor, T, seq_types)
// {
// T seq("ATCG");
// T moved(std::move(seq));
// BOOST_CHECK( seq.empty() );
// BOOST_CHECK_EQUAL(moved.size(), 4);
// auto b = moved.cbegin();
// BOOST_CHECK_EQUAL( *b , 'A');
// BOOST_CHECK_EQUAL(*(++b), 'T');
// BOOST_CHECK_EQUAL(*(++b), 'C');
// BOOST_CHECK_EQUAL(*(++b), 'G');
// }
// BOOST_AUTO_TEST_CASE_TEMPLATE(constructor_initializer_list, T, seq_types)
// {
// T seq{ 'A', 'T', 'C', 'G'};
// auto b = seq.cbegin();
// BOOST_CHECK_EQUAL( *b , 'A');
// BOOST_CHECK_EQUAL(*(++b), 'T');
// BOOST_CHECK_EQUAL(*(++b), 'C');
// BOOST_CHECK_EQUAL(*(++b), 'G');
// BOOST_CHECK_EQUAL(seq.size(), 4);
// }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment