{"action":"created","issue":{"url":"https://api.github.com/repos/boostorg/compute/issues/479","labels_url":"https://api.github.com/repos/boostorg/compute/issues/479/labels{/name}","comments_url":"https://api.github.com/repos/boostorg/compute/issues/479/comments","events_url":"https://api.github.com/repos/boostorg/compute/issues/479/events","html_url":"https://github.com/boostorg/compute/issues/479","id":95612203,"number":479,"title":"templated kernels","user":{"login":"tlgimenes","id":1753396,"avatar_url":"https://avatars.githubusercontent.com/u/1753396?v=3","gravatar_id":"","url":"https://api.github.com/users/tlgimenes","html_url":"https://github.com/tlgimenes","followers_url":"https://api.github.com/users/tlgimenes/followers","following_url":"https://api.github.com/users/tlgimenes/following{/other_user}","gists_url":"https://api.github.com/users/tlgimenes/gists{/gist_id}","starred_url":"https://api.github.com/users/tlgimenes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlgimenes/subscriptions","organizations_url":"https://api.github.com/users/tlgimenes/orgs","repos_url":"https://api.github.com/users/tlgimenes/repos","events_url":"https://api.github.com/users/tlgimenes/events{/privacy}","received_events_url":"https://api.github.com/users/tlgimenes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-17T08:27:22Z","updated_at":"2015-07-20T05:14:48Z","closed_at":null,"body":"\r\nSince not all vendor implementations today can handle templates (nvidia currently only supports OpenCL 1.2), I was wondering if it's possible to add macros and classes to Boost.Compute to parse user defined kernels containing basic templates and then generate a valid OpenCL C code for older OpenCL implementations.\r\n\r\nThe idea is basically to do something like\r\n\r\n     constexpr char type[] = BOOST_STRINGIZE_SOURCE( \r\n     struct bar \r\n     { \r\n          int a; \r\n          int b;\r\n      };\r\n      )      \r\n\r\n     constexpr char kernel_src[] = BOOST_STRINGIZE_SOURCE(\r\n     template< typename T >\r\n     __kernel foo( __global T* bar ) { } \r\n     )\r\n\r\n     constexpr char final_kernel_src = BOOST_RESOLVE_TEMPLATE( kernel_src, type );\r\n\r\nThe code above is just a demonstration of what I would like to see in Boost.Compute and I'm sure there are better solutions for the problem. I also know that modifying and compiling templated kernels is not that complicated and that each one can do that on their own code, but I would like to see a better and unified way of doing so with the use of Boost.Compute other than have to write my own code for doing this boring work every time\r\n\r\nThank you !\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/boostorg/compute/issues/comments/122765444","html_url":"https://github.com/boostorg/compute/issues/479#issuecomment-122765444","issue_url":"https://api.github.com/repos/boostorg/compute/issues/479","id":122765444,"user":{"login":"kylelutz","id":45812,"avatar_url":"https://avatars.githubusercontent.com/u/45812?v=3","gravatar_id":"","url":"https://api.github.com/users/kylelutz","html_url":"https://github.com/kylelutz","followers_url":"https://api.github.com/users/kylelutz/followers","following_url":"https://api.github.com/users/kylelutz/following{/other_user}","gists_url":"https://api.github.com/users/kylelutz/gists{/gist_id}","starred_url":"https://api.github.com/users/kylelutz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylelutz/subscriptions","organizations_url":"https://api.github.com/users/kylelutz/orgs","repos_url":"https://api.github.com/users/kylelutz/repos","events_url":"https://api.github.com/users/kylelutz/events{/privacy}","received_events_url":"https://api.github.com/users/kylelutz/received_events","type":"User","site_admin":false},"created_at":"2015-07-20T05:14:48Z","updated_at":"2015-07-20T05:14:48Z","body":"That is an interesting idea, I'll have to think about how it could be implemented. For now, the best way to do this is use `\"T\"` as a macro and then define it to your desired type (e.g. `-DT=bar` or `-DT=int`) when compiling the program.\r\n\r\nAlso, you may want to take a look at the `define()` method in the `boost::compute::function` class which allows you to define custom variables which are then compiled when the function is called.\r\n"}}