KhronosGroup / OpenCL-Registry

OpenCL API and Extension Registry.
112 stars 42 forks source link

Using the <time.h> library in opencl #75

Closed anton-kachan-dev closed 4 years ago

anton-kachan-dev commented 4 years ago

Hello !

I am new to opencl. So sorry for the possibly stupid questions.

I wanna make some time calculations on gpu (operations like add month to date, get the first day of year/month, etc). And I decided to try opencl for this. But when I started I found that the library is not available and cannot be included by a program.

Could you explain to me why i cannot use it. And may be you know some alternative ways.

The only way that I see this is to work with time in numerical format (in seconds). But I have to realize a lot of functions of the time.h library.

Thank you!

Dithermaster commented 4 years ago

OpenCL C is a restricted subset of C99, intended for execution on processors that are typically much smaller and have far fewer resources than the main CPU. Headers like time.h, STL, etc. are usually too complex for use on the GPU (or other OpenCL target, such as FPGA). I recommend you boil down the essence of what you want to compute in parallel (assuming that's why you are using OpenCL) and put just that part on the GPU, and run everything else on the CPU. In your OpenCL kernel, represent time using something quite simple (e.g., number of seconds from an epoch) and not in a complex formart (such as yy-mm-dd-hh-mm-ss).

oddhack commented 4 years ago

@KachanAnton350504 if that addresses your question, please close the issue. In general we recommend developers post API usage questions on sites like Stack Overflow - Khronos is primarily concerned with developing the specifications and related material like headers, conformance tests, and so on. Also, this repository is really just a backing store for the website, so if you have questions about the OpenCL Specification in the future, the https://github.com/KhronosGroup/OpenCL-Docs repository is the right place for that.

MathiasMagnus commented 4 years ago

@KachanAnton350504 do note that the use of the CRT is invalid in kernel code, as implementation to those are all in binary libraries (glibc.so et al) in x86_64 binary. Even if they made sense on GPU, the implementation to those functions is not accessible to the device compiler. It is not mandated for a runtime to implement those in a device compiler.

If you think some set of utilities for a given domain are missing, once you wrote them, perhaps drop them in a public repo so others won't have to do the same. :)

anton-kachan-dev commented 4 years ago

Thanks everybody!