Boost.Compute เป็นไลบรารี GPU/คู่ขนานสำหรับ C ++ ตาม OpenCL
ไลบรารีหลักคือ wrapper C ++ บาง ๆ เหนือ OpenCl API และให้การเข้าถึงอุปกรณ์คำนวณบริบทคิวคำสั่งและบัฟเฟอร์หน่วยความจำ
ด้านบนของไลบรารีหลักคืออินเตอร์เฟสทั่วไปที่มีลักษณะคล้าย STL ให้บริการอัลกอริทึมทั่วไป (เช่น transform() , accumulate() , sort() ) พร้อมกับคอนเทนเนอร์ทั่วไป (เช่น vector<T> , flat_set<T> ) นอกจากนี้ยังมีส่วนขยายจำนวนมากรวมถึงอัลกอริทึมการคำนวณแบบขนาน (เช่น exclusive_scan() , scatter() , reduce() ) และจำนวนของตัววนซ้ำแฟนซี (เช่น transform_iterator<> , permutation_iterator<> , zip_iterator<> )
เอกสารฉบับเต็มมีอยู่ที่ http://boostorg.github.io/compute/
ตัวอย่างต่อไปนี้แสดงวิธีการเรียงลำดับเวกเตอร์ของลอยบน GPU:
# include < vector >
# include < algorithm >
# include < boost/compute.hpp >
namespace compute = boost::compute;
int main ()
{
// get the default compute device
compute::device gpu = compute::system::default_device ();
// create a compute context and command queue
compute::context ctx (gpu);
compute::command_queue queue (ctx, gpu);
// generate random numbers on the host
std::vector< float > host_vector ( 1000000 );
std::generate (host_vector. begin (), host_vector. end (), rand );
// create vector on the device
compute::vector< float > device_vector ( 1000000 , ctx);
// copy data to the device
compute::copy (
host_vector. begin (), host_vector. end (), device_vector. begin (), queue
);
// sort data on the device
compute::sort (
device_vector. begin (), device_vector. end (), queue
);
// copy data back to the host
compute::copy (
device_vector. begin (), device_vector. end (), host_vector. begin (), queue
);
return 0 ;
}Boost.Compute เป็นห้องสมุดส่วนหัวเท่านั้นดังนั้นจึงไม่จำเป็นต้องเชื่อมโยง ตัวอย่างข้างต้นสามารถรวบรวมด้วย:
g++ -I/path/to/compute/include sort.cpp -lOpenCL
ตัวอย่างเพิ่มเติมสามารถพบได้ในการสอนและภายใต้ไดเรกทอรีตัวอย่าง
คำถามเกี่ยวกับห้องสมุด (ทั้งการใช้งานและการพัฒนา) สามารถโพสต์ไปยังรายชื่อผู้รับจดหมายได้
สามารถรายงานข้อบกพร่องและคุณสมบัติผ่านตัวติดตามปัญหาได้
นอกจากนี้อย่าลังเลที่จะส่งอีเมลถึงฉันพร้อมปัญหาคำถามหรือข้อเสนอแนะ
โครงการ Boost.Compute กำลังมองหานักพัฒนาเพิ่มเติมที่มีความสนใจในการคำนวณแบบขนาน
กรุณาส่งอีเมลไปที่ Kyle Lutz ([email protected]) สำหรับข้อมูลเพิ่มเติม