├── COPYING ├── COPYING.LESSER ├── LICENSE ├── Makefile ├── README ├── README.md ├── clfortran.f90 └── examples ├── basic_device_io.f90 ├── create_device_context.f90 ├── query_platforms_devices.f90 ├── sum.cl └── sum.f90 /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /COPYING.LESSER: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | 167 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # CLFORTRAN - OpenCL bindings module for Fortran. 3 | # 4 | # This is the main module file and contains all OpenCL API definitions to be 5 | # invoked from Fortran programs. 6 | # 7 | # ----------------------------------------------------------------------------- 8 | # 9 | # Copyright (C) 2013 Company for Advanced Supercomputing Solutions LTD 10 | # Bosmat 2a St. 11 | # Shoham 12 | # Israel 60850 13 | # http://www.cass-hpc.com 14 | # 15 | # Author: Mordechai Butrashvily 16 | # 17 | # ----------------------------------------------------------------------------- 18 | # 19 | # This program is free software: you can redistribute it and/or modify 20 | # it under the terms of the GNU Lesser General Public License as published by 21 | # the Free Software Foundation, either version 3 of the License, or 22 | # (at your option) any later version. 23 | # 24 | # This program is distributed in the hope that it will be useful, 25 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | # GNU Lesser General Public License for more details. 28 | # 29 | # You should have received a copy of the GNU Lesser General Public License 30 | # along with this program. If not, see . 31 | # 32 | # ----------------------------------------------------------------------------- 33 | 34 | # ----- Compiler ----- 35 | FC = gfortran 36 | #FC = ifort 37 | 38 | # OpenCL library folder (Modify for local path). 39 | CL_LIB = /usr/lib64/catalyst 40 | 41 | # ----- Build targets ----- 42 | examples: clfortran 43 | $(FC) examples/query_platforms_devices.f90 -L$(CL_LIB) -lOpenCL -o query_platforms_devices 44 | $(FC) examples/create_device_context.f90 -L$(CL_LIB) -lOpenCL -o create_device_context 45 | $(FC) examples/basic_device_io.f90 -L$(CL_LIB) -lOpenCL -o basic_device_io 46 | 47 | clfortran: clfortran.f90 48 | $(FC) -c clfortran.f90 49 | 50 | clean: 51 | rm -f query_platforms_devices create_device_context 52 | rm -f *.o *.mod 53 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | --------------- 2 | 1. Introduction 3 | --------------- 4 | CLFORTRAN is a Fortran interface to OpenCL, written in pure Fortran and 5 | compatible with OpenCL 1.2. 6 | 7 | The API CLFORTRAN exposes is identical to what developers will find with the C 8 | interface (read below for more specific details). 9 | For any question about parameters meaning, it is better to consult the official 10 | OpenCL documentation available at http://www.khronos.org. 11 | 12 | ------------------- 13 | 2. Compiler Support 14 | ------------------- 15 | To use CLFORTRAN compiler should support Fortran 2002-2003 extensions, 16 | especially ISO_C_BINDING. 17 | 18 | Most current compilers have support for this feature, including GNU, Intel and 19 | IBM. 20 | CLFORTRAN was compiled and tested with the following compilers: 21 | - gfortran (4.8.2) 22 | - ifort (13.1.1) 23 | But previous versions conforming to Fortran 2003 should work as well. 24 | 25 | ----------------------- 26 | 3. OpenCL Compatibility 27 | ----------------------- 28 | CLFORTRAN was written to provide the full API exposed by C OpenCL. 29 | 30 | However, since Fortran is case insensitive compared with C, there is a naming 31 | conflict defining constants and structures regarding the image support. 32 | 33 | In order to overcome this issue, the CL_IMAGE_* constants were renamed to begin 34 | with the following prefix: CL_IMAGE_INFO_*. 35 | Otherwise, a conflict would occur between CL_IMAGE_FORMAT and the 36 | cl_image_format structure. 37 | 38 | This is the only difference from the standard. 39 | 40 | ------------------- 41 | 4. Examples & Build 42 | ------------------- 43 | 44 | Example files are provided to demonstrate the use of CLFORTRAN and writing 45 | Fortran programs that utilize OpenCL. 46 | 47 | It is advised to consult the makefile for an example of building applications 48 | with CLFORTRAN. 49 | 50 | -------- 51 | 5. Legal 52 | -------- 53 | CLFORTRAN is licensed under LGPL, attached is a matching license. 54 | 55 | ---------------------- 56 | 6. Contact Information 57 | ---------------------- 58 | For any other issue, contact us at: support@cass-hpc.com 59 | 60 | Copyright (C) 2013-2015 Company for Advanced Supercomputing Solutions LTD 61 | 62 | Company for Advanced Supercomputing Solutions LTD 63 | Bosmat 2a St. 64 | Shoham 65 | Israel 60850 66 | http://www.cass-hpc.com 67 | 68 | Author: Mordechai Butrashvily 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | --------------- 2 | 1. Introduction 3 | --------------- 4 | CLFORTRAN is a Fortran interface to OpenCL, written in pure Fortran and 5 | compatible with OpenCL 1.2. 6 | 7 | The API CLFORTRAN exposes is identical to what developers will find with the C 8 | interface (read below for more specific details). 9 | For any question about parameters meaning, it is better to consult the official 10 | OpenCL documentation available at http://www.khronos.org. 11 | 12 | ------------------- 13 | 2. Compiler Support 14 | ------------------- 15 | To use CLFORTRAN compiler should support Fortran 2002-2003 extensions, 16 | especially ISO_C_BINDING. 17 | 18 | Most current compilers have support for this feature, including GNU, Intel and 19 | IBM. 20 | CLFORTRAN was compiled and tested with the following compilers: 21 | - gfortran (4.8.2) 22 | - ifort (13.1.1) 23 | But previous versions conforming to Fortran 2003 should work as well. 24 | 25 | ----------------------- 26 | 3. OpenCL Compatibility 27 | ----------------------- 28 | CLFORTRAN was written to provide the full API exposed by C OpenCL. 29 | 30 | However, since Fortran is case insensitive compared with C, there is a naming 31 | conflict defining constants and structures regarding the image support. 32 | 33 | In order to overcome this issue, the CL_IMAGE_* constants were renamed to begin 34 | with the following prefix: CL_IMAGE_INFO_*. 35 | Otherwise, a conflict would occur between CL_IMAGE_FORMAT and the 36 | cl_image_format structure. 37 | 38 | This is the only difference from the standard. 39 | 40 | ------------------- 41 | 4. Examples & Build 42 | ------------------- 43 | 44 | Example files are provided to demonstrate the use of CLFORTRAN and writing 45 | Fortran programs that utilize OpenCL. 46 | 47 | It is advised to consult the makefile for an example of building applications 48 | with CLFORTRAN. 49 | 50 | -------- 51 | 5. Legal 52 | -------- 53 | CLFORTRAN is licensed under LGPL, attached is a matching license. 54 | 55 | ---------------------- 56 | 6. Contact Information 57 | ---------------------- 58 | For any other issue, contact us at: support@cass-hpc.com 59 | 60 | Copyright (C) 2013-2015 Company for Advanced Supercomputing Solutions LTD 61 | 62 | Company for Advanced Supercomputing Solutions LTD 63 | Bosmat 2a St. 64 | Shoham 65 | Israel 60850 66 | http://www.cass-hpc.com 67 | 68 | Author: Mordechai Butrashvily 69 | -------------------------------------------------------------------------------- /clfortran.f90: -------------------------------------------------------------------------------- 1 | ! ----------------------------------------------------------------------------- 2 | ! CLFORTRAN - OpenCL bindings module for Fortran. 3 | ! 4 | ! This is the main module file and contains all OpenCL API definitions to be 5 | ! invoked from Fortran programs. 6 | ! 7 | ! ----------------------------------------------------------------------------- 8 | ! 9 | ! Copyright (C) 2013 Company for Advanced Supercomputing Solutions LTD 10 | ! Bosmat 2a St. 11 | ! Shoham 12 | ! Israel 60850 13 | ! http://www.cass-hpc.com 14 | ! 15 | ! Author: Mordechai Butrashvily 16 | ! 17 | ! ----------------------------------------------------------------------------- 18 | ! 19 | ! This program is free software: you can redistribute it and/or modify 20 | ! it under the terms of the GNU Lesser General Public License as published by 21 | ! the Free Software Foundation, either version 3 of the License, or 22 | ! (at your option) any later version. 23 | ! 24 | ! This program is distributed in the hope that it will be useful, 25 | ! but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | ! GNU Lesser General Public License for more details. 28 | ! 29 | ! You should have received a copy of the GNU Lesser General Public License 30 | ! along with this program. If not, see . 31 | ! 32 | ! ----------------------------------------------------------------------------- 33 | 34 | module clfortran 35 | USE ISO_C_BINDING 36 | implicit none 37 | 38 | ! Error Codes 39 | integer(c_int32_t), parameter :: CL_SUCCESS = 0 40 | integer(c_int32_t), parameter :: CL_DEVICE_NOT_FOUND = -1 41 | integer(c_int32_t), parameter :: CL_DEVICE_NOT_AVAILABLE = -2 42 | integer(c_int32_t), parameter :: CL_COMPILER_NOT_AVAILABLE = -3 43 | integer(c_int32_t), parameter :: CL_MEM_OBJECT_ALLOCATION_FAILURE = -4 44 | integer(c_int32_t), parameter :: CL_OUT_OF_RESOURCES = -5 45 | integer(c_int32_t), parameter :: CL_OUT_OF_HOST_MEMORY = -6 46 | integer(c_int32_t), parameter :: CL_PROFILING_INFO_NOT_AVAILABLE = -7 47 | integer(c_int32_t), parameter :: CL_MEM_COPY_OVERLAP = -8 48 | integer(c_int32_t), parameter :: CL_IMAGE_FORMAT_MISMATCH = -9 49 | integer(c_int32_t), parameter :: CL_IMAGE_FORMAT_NOT_SUPPORTED = -10 50 | integer(c_int32_t), parameter :: CL_BUILD_PROGRAM_FAILURE = -11 51 | integer(c_int32_t), parameter :: CL_MAP_FAILURE = -12 52 | integer(c_int32_t), parameter :: CL_MISALIGNED_SUB_BUFFER_OFFSET = -13 53 | integer(c_int32_t), parameter :: CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST = -14 54 | integer(c_int32_t), parameter :: CL_COMPILE_PROGRAM_FAILURE = -15 55 | integer(c_int32_t), parameter :: CL_LINKER_NOT_AVAILABLE = -16 56 | integer(c_int32_t), parameter :: CL_LINK_PROGRAM_FAILURE = -17 57 | integer(c_int32_t), parameter :: CL_DEVICE_PARTITION_FAILED = -18 58 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_INFO_NOT_AVAILABLE = -19 59 | 60 | integer(c_int32_t), parameter :: CL_INVALID_VALUE = -30 61 | integer(c_int32_t), parameter :: CL_INVALID_DEVICE_TYPE = -31 62 | integer(c_int32_t), parameter :: CL_INVALID_PLATFORM = -32 63 | integer(c_int32_t), parameter :: CL_INVALID_DEVICE = -33 64 | integer(c_int32_t), parameter :: CL_INVALID_CONTEXT = -34 65 | integer(c_int32_t), parameter :: CL_INVALID_QUEUE_PROPERTIES = -35 66 | integer(c_int32_t), parameter :: CL_INVALID_COMMAND_QUEUE = -36 67 | integer(c_int32_t), parameter :: CL_INVALID_HOST_PTR = -37 68 | integer(c_int32_t), parameter :: CL_INVALID_MEM_OBJECT = -38 69 | integer(c_int32_t), parameter :: CL_INVALID_IMAGE_FORMAT_DESCRIPTOR = -39 70 | integer(c_int32_t), parameter :: CL_INVALID_IMAGE_SIZE = -40 71 | integer(c_int32_t), parameter :: CL_INVALID_SAMPLER = -41 72 | integer(c_int32_t), parameter :: CL_INVALID_BINARY = -42 73 | integer(c_int32_t), parameter :: CL_INVALID_BUILD_OPTIONS = -43 74 | integer(c_int32_t), parameter :: CL_INVALID_PROGRAM = -44 75 | integer(c_int32_t), parameter :: CL_INVALID_PROGRAM_EXECUTABLE = -45 76 | integer(c_int32_t), parameter :: CL_INVALID_KERNEL_NAME = -46 77 | integer(c_int32_t), parameter :: CL_INVALID_KERNEL_DEFINITION = -47 78 | integer(c_int32_t), parameter :: CL_INVALID_KERNEL = -48 79 | integer(c_int32_t), parameter :: CL_INVALID_ARG_INDEX = -49 80 | integer(c_int32_t), parameter :: CL_INVALID_ARG_VALUE = -50 81 | integer(c_int32_t), parameter :: CL_INVALID_ARG_SIZE = -51 82 | integer(c_int32_t), parameter :: CL_INVALID_KERNEL_ARGS = -52 83 | integer(c_int32_t), parameter :: CL_INVALID_WORK_DIMENSION = -53 84 | integer(c_int32_t), parameter :: CL_INVALID_WORK_GROUP_SIZE = -54 85 | integer(c_int32_t), parameter :: CL_INVALID_WORK_ITEM_SIZE = -55 86 | integer(c_int32_t), parameter :: CL_INVALID_GLOBAL_OFFSET = -56 87 | integer(c_int32_t), parameter :: CL_INVALID_EVENT_WAIT_LIST = -57 88 | integer(c_int32_t), parameter :: CL_INVALID_EVENT = -58 89 | integer(c_int32_t), parameter :: CL_INVALID_OPERATION = -59 90 | integer(c_int32_t), parameter :: CL_INVALID_GL_OBJECT = -60 91 | integer(c_int32_t), parameter :: CL_INVALID_BUFFER_SIZE = -61 92 | integer(c_int32_t), parameter :: CL_INVALID_MIP_LEVEL = -62 93 | integer(c_int32_t), parameter :: CL_INVALID_GLOBAL_WORK_SIZE = -63 94 | integer(c_int32_t), parameter :: CL_INVALID_PROPERTY = -64 95 | integer(c_int32_t), parameter :: CL_INVALID_IMAGE_DESCRIPTOR = -65 96 | integer(c_int32_t), parameter :: CL_INVALID_COMPILER_OPTIONS = -66 97 | integer(c_int32_t), parameter :: CL_INVALID_LINKER_OPTIONS = -67 98 | integer(c_int32_t), parameter :: CL_INVALID_DEVICE_PARTITION_COUNT = -68 99 | 100 | ! OpenCL Version 101 | integer(c_int32_t), parameter :: CL_VERSION_1_0 = 1 102 | integer(c_int32_t), parameter :: CL_VERSION_1_1 = 1 103 | integer(c_int32_t), parameter :: CL_VERSION_1_2 = 1 104 | 105 | ! cl_bool 106 | integer(c_int32_t), parameter :: CL_FALSE = 0 107 | integer(c_int32_t), parameter :: CL_TRUE = 1 108 | integer(c_int32_t), parameter :: CL_BLOCKING = CL_TRUE 109 | integer(c_int32_t), parameter :: CL_NON_BLOCKING = CL_FALSE 110 | 111 | ! cl_platform_info 112 | integer(c_int32_t), parameter :: CL_PLATFORM_PROFILE = Z'0900' 113 | integer(c_int32_t), parameter :: CL_PLATFORM_VERSION = Z'0901' 114 | integer(c_int32_t), parameter :: CL_PLATFORM_NAME = Z'0902' 115 | integer(c_int32_t), parameter :: CL_PLATFORM_VENDOR = Z'0903' 116 | integer(c_int32_t), parameter :: CL_PLATFORM_EXTENSIONS = Z'0904' 117 | 118 | ! cl_device_type - bitfield 119 | integer(c_int64_t), parameter :: CL_DEVICE_TYPE_DEFAULT = b'00001' 120 | integer(c_int64_t), parameter :: CL_DEVICE_TYPE_CPU = b'00010' 121 | integer(c_int64_t), parameter :: CL_DEVICE_TYPE_GPU = b'00100' 122 | integer(c_int64_t), parameter :: CL_DEVICE_TYPE_ACCELERATOR = b'01000' 123 | integer(c_int64_t), parameter :: CL_DEVICE_TYPE_CUSTOM = b'10000' 124 | integer(c_int64_t), parameter :: CL_DEVICE_TYPE_ALL = Z'FFFFFFFF' 125 | 126 | ! cl_device_info 127 | integer(c_int32_t), parameter :: CL_DEVICE_TYPE = Z'1000' 128 | integer(c_int32_t), parameter :: CL_DEVICE_VENDOR_ID = Z'1001' 129 | integer(c_int32_t), parameter :: CL_DEVICE_MAX_COMPUTE_UNITS = Z'1002' 130 | integer(c_int32_t), parameter :: CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS = Z'1003' 131 | integer(c_int32_t), parameter :: CL_DEVICE_MAX_WORK_GROUP_SIZE = Z'1004' 132 | integer(c_int32_t), parameter :: CL_DEVICE_MAX_WORK_ITEM_SIZES = Z'1005' 133 | integer(c_int32_t), parameter :: CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR = Z'1006' 134 | integer(c_int32_t), parameter :: CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT = Z'1007' 135 | integer(c_int32_t), parameter :: CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT = Z'1008' 136 | integer(c_int32_t), parameter :: CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG = Z'1009' 137 | integer(c_int32_t), parameter :: CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT = Z'100A' 138 | integer(c_int32_t), parameter :: CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE = Z'100B' 139 | integer(c_int32_t), parameter :: CL_DEVICE_MAX_CLOCK_FREQUENCY = Z'100C' 140 | integer(c_int32_t), parameter :: CL_DEVICE_ADDRESS_BITS = Z'100D' 141 | integer(c_int32_t), parameter :: CL_DEVICE_MAX_READ_IMAGE_ARGS = Z'100E' 142 | integer(c_int32_t), parameter :: CL_DEVICE_MAX_WRITE_IMAGE_ARGS = Z'100F' 143 | integer(c_int32_t), parameter :: CL_DEVICE_MAX_MEM_ALLOC_SIZE = Z'1010' 144 | integer(c_int32_t), parameter :: CL_DEVICE_IMAGE2D_MAX_WIDTH = Z'1011' 145 | integer(c_int32_t), parameter :: CL_DEVICE_IMAGE2D_MAX_HEIGHT = Z'1012' 146 | integer(c_int32_t), parameter :: CL_DEVICE_IMAGE3D_MAX_WIDTH = Z'1013' 147 | integer(c_int32_t), parameter :: CL_DEVICE_IMAGE3D_MAX_HEIGHT = Z'1014' 148 | integer(c_int32_t), parameter :: CL_DEVICE_IMAGE3D_MAX_DEPTH = Z'1015' 149 | integer(c_int32_t), parameter :: CL_DEVICE_IMAGE_SUPPORT = Z'1016' 150 | integer(c_int32_t), parameter :: CL_DEVICE_MAX_PARAMETER_SIZE = Z'1017' 151 | integer(c_int32_t), parameter :: CL_DEVICE_MAX_SAMPLERS = Z'1018' 152 | integer(c_int32_t), parameter :: CL_DEVICE_MEM_BASE_ADDR_ALIGN = Z'1019' 153 | integer(c_int32_t), parameter :: CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE = Z'101A' 154 | integer(c_int32_t), parameter :: CL_DEVICE_SINGLE_FP_CONFIG = Z'101B' 155 | integer(c_int32_t), parameter :: CL_DEVICE_GLOBAL_MEM_CACHE_TYPE = Z'101C' 156 | integer(c_int32_t), parameter :: CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE = Z'101D' 157 | integer(c_int32_t), parameter :: CL_DEVICE_GLOBAL_MEM_CACHE_SIZE = Z'101E' 158 | integer(c_int32_t), parameter :: CL_DEVICE_GLOBAL_MEM_SIZE = Z'101F' 159 | integer(c_int32_t), parameter :: CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE = Z'1020' 160 | integer(c_int32_t), parameter :: CL_DEVICE_MAX_CONSTANT_ARGS = Z'1021' 161 | integer(c_int32_t), parameter :: CL_DEVICE_LOCAL_MEM_TYPE = Z'1022' 162 | integer(c_int32_t), parameter :: CL_DEVICE_LOCAL_MEM_SIZE = Z'1023' 163 | integer(c_int32_t), parameter :: CL_DEVICE_ERROR_CORRECTION_SUPPORT = Z'1024' 164 | integer(c_int32_t), parameter :: CL_DEVICE_PROFILING_TIMER_RESOLUTION = Z'1025' 165 | integer(c_int32_t), parameter :: CL_DEVICE_ENDIAN_LITTLE = Z'1026' 166 | integer(c_int32_t), parameter :: CL_DEVICE_AVAILABLE = Z'1027' 167 | integer(c_int32_t), parameter :: CL_DEVICE_COMPILER_AVAILABLE = Z'1028' 168 | integer(c_int32_t), parameter :: CL_DEVICE_EXECUTION_CAPABILITIES = Z'1029' 169 | integer(c_int32_t), parameter :: CL_DEVICE_QUEUE_PROPERTIES = Z'102A' 170 | integer(c_int32_t), parameter :: CL_DEVICE_NAME = Z'102B' 171 | integer(c_int32_t), parameter :: CL_DEVICE_VENDOR = Z'102C' 172 | integer(c_int32_t), parameter :: CL_DRIVER_VERSION = Z'102D' 173 | integer(c_int32_t), parameter :: CL_DEVICE_PROFILE = Z'102E' 174 | integer(c_int32_t), parameter :: CL_DEVICE_VERSION = Z'102F' 175 | integer(c_int32_t), parameter :: CL_DEVICE_EXTENSIONS = Z'1030' 176 | integer(c_int32_t), parameter :: CL_DEVICE_PLATFORM = Z'1031' 177 | integer(c_int32_t), parameter :: CL_DEVICE_DOUBLE_FP_CONFIG = Z'1032' 178 | ! 0x1033 reserved for CL_DEVICE_HALF_FP_CONFIG 179 | integer(c_int32_t), parameter :: CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF = Z'1034' 180 | integer(c_int32_t), parameter :: CL_DEVICE_HOST_UNIFIED_MEMORY = Z'1035' 181 | integer(c_int32_t), parameter :: CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR = Z'1036' 182 | integer(c_int32_t), parameter :: CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT = Z'1037' 183 | integer(c_int32_t), parameter :: CL_DEVICE_NATIVE_VECTOR_WIDTH_INT = Z'1038' 184 | integer(c_int32_t), parameter :: CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG = Z'1039' 185 | integer(c_int32_t), parameter :: CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT = Z'103A' 186 | integer(c_int32_t), parameter :: CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE = Z'103B' 187 | integer(c_int32_t), parameter :: CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF = Z'103C' 188 | integer(c_int32_t), parameter :: CL_DEVICE_OPENCL_C_VERSION = Z'103D' 189 | integer(c_int32_t), parameter :: CL_DEVICE_LINKER_AVAILABLE = Z'103E' 190 | integer(c_int32_t), parameter :: CL_DEVICE_BUILT_IN_KERNELS = Z'103F' 191 | integer(c_int32_t), parameter :: CL_DEVICE_IMAGE_MAX_BUFFER_SIZE = Z'1040' 192 | integer(c_int32_t), parameter :: CL_DEVICE_IMAGE_MAX_ARRAY_SIZE = Z'1041' 193 | integer(c_int32_t), parameter :: CL_DEVICE_PARENT_DEVICE = Z'1042' 194 | integer(c_int32_t), parameter :: CL_DEVICE_PARTITION_MAX_SUB_DEVICES = Z'1043' 195 | integer(c_int32_t), parameter :: CL_DEVICE_PARTITION_PROPERTIES = Z'1044' 196 | integer(c_int32_t), parameter :: CL_DEVICE_PARTITION_AFFINITY_DOMAIN = Z'1045' 197 | integer(c_int32_t), parameter :: CL_DEVICE_PARTITION_TYPE = Z'1046' 198 | integer(c_int32_t), parameter :: CL_DEVICE_REFERENCE_COUNT = Z'1047' 199 | integer(c_int32_t), parameter :: CL_DEVICE_PREFERRED_INTEROP_USER_SYNC = Z'1048' 200 | integer(c_int32_t), parameter :: CL_DEVICE_PRINTF_BUFFER_SIZE = Z'1049' 201 | 202 | ! cl_device_fp_config - bitfield 203 | integer(c_int64_t), parameter :: CL_FP_DENORM = b'00000001' 204 | integer(c_int64_t), parameter :: CL_FP_INF_NAN = b'00000010' 205 | integer(c_int64_t), parameter :: CL_FP_ROUND_TO_NEAREST = b'00000100' 206 | integer(c_int64_t), parameter :: CL_FP_ROUND_TO_ZERO = b'00001000' 207 | integer(c_int64_t), parameter :: CL_FP_ROUND_TO_INF = b'00010000' 208 | integer(c_int64_t), parameter :: CL_FP_FMA = b'00100000' 209 | integer(c_int64_t), parameter :: CL_FP_SOFT_FLOAT = b'01000000' 210 | integer(c_int64_t), parameter :: CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT = b'10000000' 211 | 212 | ! cl_device_mem_cache_type 213 | integer(c_int32_t), parameter :: CL_NONE = Z'0' 214 | integer(c_int32_t), parameter :: CL_READ_ONLY_CACHE = Z'1' 215 | integer(c_int32_t), parameter :: CL_READ_WRITE_CACHE = Z'2' 216 | 217 | ! cl_device_local_mem_type 218 | integer(c_int32_t), parameter :: CL_LOCAL = Z'1' 219 | integer(c_int32_t), parameter :: CL_GLOBAL = Z'2' 220 | 221 | ! cl_device_exec_capabilities - bitfield 222 | integer(c_int64_t), parameter :: CL_EXEC_KERNEL = b'01' 223 | integer(c_int64_t), parameter :: CL_EXEC_NATIVE_KERNEL = b'10' 224 | 225 | ! cl_command_queue_properties - bitfield 226 | integer(c_int64_t), parameter :: CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE = b'01' 227 | integer(c_int64_t), parameter :: CL_QUEUE_PROFILING_ENABLE = b'10' 228 | 229 | ! cl_context_info 230 | integer(c_int32_t), parameter :: CL_CONTEXT_REFERENCE_COUNT = Z'1080' 231 | integer(c_int32_t), parameter :: CL_CONTEXT_DEVICES = Z'1081' 232 | integer(c_int32_t), parameter :: CL_CONTEXT_PROPERTIES = Z'1082' 233 | integer(c_int32_t), parameter :: CL_CONTEXT_NUM_DEVICES = Z'1083' 234 | 235 | ! cl_context_properties type(c_ptr) 236 | integer(c_intptr_t), parameter :: CL_CONTEXT_PLATFORM = Z'1084' 237 | integer(c_intptr_t), parameter :: CL_CONTEXT_INTEROP_USER_SYNC = Z'1085' 238 | 239 | ! cl_command_queue_info 240 | integer(c_int32_t), parameter :: CL_QUEUE_CONTEXT = Z'1090' 241 | integer(c_int32_t), parameter :: CL_QUEUE_DEVICE = Z'1091' 242 | integer(c_int32_t), parameter :: CL_QUEUE_REFERENCE_COUNT = Z'1092' 243 | integer(c_int32_t), parameter :: CL_QUEUE_PROPERTIES = Z'1093' 244 | 245 | ! cl_mem_flags - bitfield (int64) 246 | integer(c_int64_t), parameter :: CL_MEM_READ_WRITE = b'0000000001' 247 | integer(c_int64_t), parameter :: CL_MEM_WRITE_ONLY = b'0000000010' 248 | integer(c_int64_t), parameter :: CL_MEM_READ_ONLY = b'0000000100' 249 | integer(c_int64_t), parameter :: CL_MEM_USE_HOST_PTR = b'0000001000' 250 | integer(c_int64_t), parameter :: CL_MEM_ALLOC_HOST_PTR = b'0000010000' 251 | integer(c_int64_t), parameter :: CL_MEM_COPY_HOST_PTR = b'0000100000' 252 | !integer(c_int64_t), parameter :: reserved = b'0001000000' 253 | integer(c_int64_t), parameter :: CL_MEM_HOST_WRITE_ONLY = b'0010000000' 254 | integer(c_int64_t), parameter :: CL_MEM_HOST_READ_ONLY = b'0100000000' 255 | integer(c_int64_t), parameter :: CL_MEM_HOST_NO_ACCESS = b'1000000000' 256 | 257 | ! cl_buffer_create_type 258 | integer(c_int32_t), parameter :: CL_BUFFER_CREATE_TYPE_REGION = Z'1220' 259 | 260 | ! cl_channel_order 261 | integer(c_int32_t), parameter :: CL_R = Z'10B0' 262 | integer(c_int32_t), parameter :: CL_A = Z'10B1' 263 | integer(c_int32_t), parameter :: CL_RG = Z'10B2' 264 | integer(c_int32_t), parameter :: CL_RA = Z'10B3' 265 | integer(c_int32_t), parameter :: CL_RGB = Z'10B4' 266 | integer(c_int32_t), parameter :: CL_RGBA = Z'10B5' 267 | integer(c_int32_t), parameter :: CL_BGRA = Z'10B6' 268 | integer(c_int32_t), parameter :: CL_ARGB = Z'10B7' 269 | integer(c_int32_t), parameter :: CL_INTENSITY = Z'10B8' 270 | integer(c_int32_t), parameter :: CL_LUMINANCE = Z'10B9' 271 | integer(c_int32_t), parameter :: CL_Rx = Z'10BA' 272 | integer(c_int32_t), parameter :: CL_RGx = Z'10BB' 273 | integer(c_int32_t), parameter :: CL_RGBx = Z'10BC' 274 | integer(c_int32_t), parameter :: CL_DEPTH = Z'10BD' 275 | integer(c_int32_t), parameter :: CL_DEPTH_STENCIL = Z'10BE' 276 | 277 | ! cl_channel_type 278 | integer(c_int32_t), parameter :: CL_SNORM_INT8 = Z'10D0' 279 | integer(c_int32_t), parameter :: CL_SNORM_INT16 = Z'10D1' 280 | integer(c_int32_t), parameter :: CL_UNORM_INT8 = Z'10D2' 281 | integer(c_int32_t), parameter :: CL_UNORM_INT16 = Z'10D3' 282 | integer(c_int32_t), parameter :: CL_UNORM_SHORT_565 = Z'10D4' 283 | integer(c_int32_t), parameter :: CL_UNORM_SHORT_555 = Z'10D5' 284 | integer(c_int32_t), parameter :: CL_UNORM_INT_101010 = Z'10D6' 285 | integer(c_int32_t), parameter :: CL_SIGNED_INT8 = Z'10D7' 286 | integer(c_int32_t), parameter :: CL_SIGNED_INT16 = Z'10D8' 287 | integer(c_int32_t), parameter :: CL_SIGNED_INT32 = Z'10D9' 288 | integer(c_int32_t), parameter :: CL_UNSIGNED_INT8 = Z'10DA' 289 | integer(c_int32_t), parameter :: CL_UNSIGNED_INT16 = Z'10DB' 290 | integer(c_int32_t), parameter :: CL_UNSIGNED_INT32 = Z'10DC' 291 | integer(c_int32_t), parameter :: CL_HALF_FLOAT = Z'10DD' 292 | integer(c_int32_t), parameter :: CL_FLOAT = Z'10DE' 293 | integer(c_int32_t), parameter :: CL_UNORM_INT24 = Z'10DF' 294 | 295 | ! cl_mem_object_type 296 | integer(c_int32_t), parameter :: CL_MEM_OBJECT_BUFFER = Z'10F0' 297 | integer(c_int32_t), parameter :: CL_MEM_OBJECT_IMAGE2D = Z'10F1' 298 | integer(c_int32_t), parameter :: CL_MEM_OBJECT_IMAGE3D = Z'10F2' 299 | integer(c_int32_t), parameter :: CL_MEM_OBJECT_IMAGE2D_ARRAY = Z'10F3' 300 | integer(c_int32_t), parameter :: CL_MEM_OBJECT_IMAGE1D = Z'10F4' 301 | integer(c_int32_t), parameter :: CL_MEM_OBJECT_IMAGE1D_ARRAY = Z'10F5' 302 | integer(c_int32_t), parameter :: CL_MEM_OBJECT_IMAGE1D_BUFFER = Z'10F6' 303 | 304 | ! cl_mem_info 305 | integer(c_int32_t), parameter :: CL_MEM_TYPE = Z'1100' 306 | integer(c_int32_t), parameter :: CL_MEM_FLAGS = Z'1101' 307 | integer(c_int32_t), parameter :: CL_MEM_SIZE = Z'1102' 308 | integer(c_int32_t), parameter :: CL_MEM_HOST_PTR = Z'1103' 309 | integer(c_int32_t), parameter :: CL_MEM_MAP_COUNT = Z'1104' 310 | integer(c_int32_t), parameter :: CL_MEM_REFERENCE_COUNT = Z'1105' 311 | integer(c_int32_t), parameter :: CL_MEM_CONTEXT = Z'1106' 312 | integer(c_int32_t), parameter :: CL_MEM_ASSOCIATED_MEMOBJECT = Z'1107' 313 | integer(c_int32_t), parameter :: CL_MEM_OFFSET = Z'1108' 314 | 315 | ! cl_image_info - Note that INFO was added to resolve naming conflicts. 316 | integer(c_int32_t), parameter :: CL_IMAGE_INFO_FORMAT = Z'1110' 317 | integer(c_int32_t), parameter :: CL_IMAGE_INFO_ELEMENT_SIZE = Z'1111' 318 | integer(c_int32_t), parameter :: CL_IMAGE_INFO_ROW_PITCH = Z'1112' 319 | integer(c_int32_t), parameter :: CL_IMAGE_INFO_SLICE_PITCH = Z'1113' 320 | integer(c_int32_t), parameter :: CL_IMAGE_INFO_WIDTH = Z'1114' 321 | integer(c_int32_t), parameter :: CL_IMAGE_INFO_HEIGHT = Z'1115' 322 | integer(c_int32_t), parameter :: CL_IMAGE_INFO_DEPTH = Z'1116' 323 | integer(c_int32_t), parameter :: CL_IMAGE_INFO_ARRAY_SIZE = Z'1117' 324 | integer(c_int32_t), parameter :: CL_IMAGE_INFO_BUFFER = Z'1118' 325 | integer(c_int32_t), parameter :: CL_IMAGE_INFO_NUM_MIP_LEVELS = Z'1119' 326 | integer(c_int32_t), parameter :: CL_IMAGE_INFO_NUM_SAMPLES = Z'111A' 327 | 328 | ! cl_addressing_mode 329 | integer(c_int32_t), parameter :: CL_ADDRESS_NONE = Z'1130' 330 | integer(c_int32_t), parameter :: CL_ADDRESS_CLAMP_TO_EDGE = Z'1131' 331 | integer(c_int32_t), parameter :: CL_ADDRESS_CLAMP = Z'1132' 332 | integer(c_int32_t), parameter :: CL_ADDRESS_REPEAT = Z'1133' 333 | integer(c_int32_t), parameter :: CL_ADDRESS_MIRRORED_REPEAT = Z'1134' 334 | 335 | ! cl_filter_mode 336 | integer(c_int32_t), parameter :: CL_FILTER_NEAREST = Z'1140' 337 | integer(c_int32_t), parameter :: CL_FILTER_LINEAR = Z'1141' 338 | 339 | ! cl_sampler_info 340 | integer(c_int32_t), parameter :: CL_SAMPLER_REFERENCE_COUNT = Z'1150' 341 | integer(c_int32_t), parameter :: CL_SAMPLER_CONTEXT = Z'1151' 342 | integer(c_int32_t), parameter :: CL_SAMPLER_NORMALIZED_COORDS = Z'1152' 343 | integer(c_int32_t), parameter :: CL_SAMPLER_ADDRESSING_MODE = Z'1153' 344 | integer(c_int32_t), parameter :: CL_SAMPLER_FILTER_MODE = Z'1154' 345 | 346 | ! cl_program_info 347 | integer(c_int32_t), parameter :: CL_PROGRAM_REFERENCE_COUNT = Z'1160' 348 | integer(c_int32_t), parameter :: CL_PROGRAM_CONTEXT = Z'1161' 349 | integer(c_int32_t), parameter :: CL_PROGRAM_NUM_DEVICES = Z'1162' 350 | integer(c_int32_t), parameter :: CL_PROGRAM_DEVICES = Z'1163' 351 | integer(c_int32_t), parameter :: CL_PROGRAM_SOURCE = Z'1164' 352 | integer(c_int32_t), parameter :: CL_PROGRAM_BINARY_SIZES = Z'1165' 353 | integer(c_int32_t), parameter :: CL_PROGRAM_BINARIES = Z'1166' 354 | integer(c_int32_t), parameter :: CL_PROGRAM_NUM_KERNELS = Z'1167' 355 | integer(c_int32_t), parameter :: CL_PROGRAM_KERNEL_NAMES = Z'1168' 356 | 357 | ! cl_program_build_info 358 | integer(c_int32_t), parameter :: CL_PROGRAM_BUILD_STATUS = Z'1181' 359 | integer(c_int32_t), parameter :: CL_PROGRAM_BUILD_OPTIONS = Z'1182' 360 | integer(c_int32_t), parameter :: CL_PROGRAM_BUILD_LOG = Z'1183' 361 | integer(c_int32_t), parameter :: CL_PROGRAM_BINARY_TYPE = Z'1184' 362 | 363 | ! cl_program_binary_type 364 | integer(c_int32_t), parameter :: CL_PROGRAM_BINARY_TYPE_NONE = Z'0' 365 | integer(c_int32_t), parameter :: CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT = Z'1' 366 | integer(c_int32_t), parameter :: CL_PROGRAM_BINARY_TYPE_LIBRARY = Z'2' 367 | integer(c_int32_t), parameter :: CL_PROGRAM_BINARY_TYPE_EXECUTABLE = Z'4' 368 | 369 | ! cl_build_status 370 | integer(c_int32_t), parameter :: CL_BUILD_SUCCESS = 0 371 | integer(c_int32_t), parameter :: CL_BUILD_NONE = -1 372 | integer(c_int32_t), parameter :: CL_BUILD_ERROR = -2 373 | integer(c_int32_t), parameter :: CL_BUILD_IN_PROGRESS = -3 374 | 375 | ! cl_kernel_info 376 | integer(c_int32_t), parameter :: CL_KERNEL_FUNCTION_NAME = Z'1190' 377 | integer(c_int32_t), parameter :: CL_KERNEL_NUM_ARGS = Z'1191' 378 | integer(c_int32_t), parameter :: CL_KERNEL_REFERENCE_COUNT = Z'1192' 379 | integer(c_int32_t), parameter :: CL_KERNEL_CONTEXT = Z'1193' 380 | integer(c_int32_t), parameter :: CL_KERNEL_PROGRAM = Z'1194' 381 | integer(c_int32_t), parameter :: CL_KERNEL_ATTRIBUTES = Z'1195' 382 | 383 | ! cl_kernel_arg_info 384 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_ADDRESS_QUALIFIER = Z'1196' 385 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_ACCESS_QUALIFIER = Z'1197' 386 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_TYPE_NAME = Z'1198' 387 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_TYPE_QUALIFIER = Z'1199' 388 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_NAME = Z'119A' 389 | 390 | ! cl_kernel_arg_address_qualifier 391 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_ADDRESS_GLOBAL = Z'119B' 392 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_ADDRESS_LOCAL = Z'119C' 393 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_ADDRESS_CONSTANT = Z'119D' 394 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_ADDRESS_PRIVATE = Z'119E' 395 | 396 | ! cl_kernel_arg_access_qualifier 397 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_ACCESS_READ_ONLY = Z'11A0' 398 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_ACCESS_WRITE_ONLY = Z'11A1' 399 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_ACCESS_READ_WRITE = Z'11A2' 400 | integer(c_int32_t), parameter :: CL_KERNEL_ARG_ACCESS_NONE = Z'11A3' 401 | 402 | ! cl_kernel_arg_type_qualifer - bitfield (int64) 403 | integer(c_int64_t), parameter :: CL_KERNEL_ARG_TYPE_NONE = b'000' 404 | integer(c_int64_t), parameter :: CL_KERNEL_ARG_TYPE_CONST = b'001' 405 | integer(c_int64_t), parameter :: CL_KERNEL_ARG_TYPE_RESTRICT = b'010' 406 | integer(c_int64_t), parameter :: CL_KERNEL_ARG_TYPE_VOLATILE = b'100' 407 | 408 | ! cl_kernel_work_group_info 409 | integer(c_int32_t), parameter :: CL_KERNEL_WORK_GROUP_SIZE = Z'11B0' 410 | integer(c_int32_t), parameter :: CL_KERNEL_COMPILE_WORK_GROUP_SIZE = Z'11B1' 411 | integer(c_int32_t), parameter :: CL_KERNEL_LOCAL_MEM_SIZE = Z'11B2' 412 | integer(c_int32_t), parameter :: CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE= Z'11B3' 413 | integer(c_int32_t), parameter :: CL_KERNEL_PRIVATE_MEM_SIZE = Z'11B4' 414 | integer(c_int32_t), parameter :: CL_KERNEL_GLOBAL_WORK_SIZE = Z'11B5' 415 | 416 | ! cl_event_info 417 | integer(c_int32_t), parameter :: CL_EVENT_COMMAND_QUEUE = Z'11D0' 418 | integer(c_int32_t), parameter :: CL_EVENT_COMMAND_TYPE = Z'11D1' 419 | integer(c_int32_t), parameter :: CL_EVENT_REFERENCE_COUNT = Z'11D2' 420 | integer(c_int32_t), parameter :: CL_EVENT_COMMAND_EXECUTION_STATUS = Z'11D3' 421 | integer(c_int32_t), parameter :: CL_EVENT_CONTEXT = Z'11D4' 422 | 423 | ! cl_profiling_info 424 | integer(c_int32_t), parameter :: CL_PROFILING_COMMAND_QUEUED = Z'1280' 425 | integer(c_int32_t), parameter :: CL_PROFILING_COMMAND_SUBMIT = Z'1281' 426 | integer(c_int32_t), parameter :: CL_PROFILING_COMMAND_START = Z'1282' 427 | integer(c_int32_t), parameter :: CL_PROFILING_COMMAND_END = Z'1283' 428 | 429 | ! ------------ 430 | ! Types 431 | ! ------------ 432 | 433 | type, BIND(C) :: cl_image_format 434 | integer(c_int32_t) :: image_channel_order 435 | integer(c_int32_t) :: image_channel_data_type 436 | end type 437 | 438 | type, BIND(C) :: cl_image_desc 439 | integer(c_int32_t) :: image_type 440 | integer(c_size_t) :: image_width 441 | integer(c_size_t) :: image_height 442 | integer(c_size_t) :: image_depth 443 | integer(c_size_t) :: image_array_size 444 | integer(c_size_t) :: image_row_pitch 445 | integer(c_size_t) :: image_slice_pitch 446 | integer(c_int32_t) :: num_mip_levels 447 | integer(c_int32_t) :: num_samples 448 | integer(c_intptr_t) :: buffer 449 | end type 450 | 451 | 452 | ! 453 | ! Start interfaces. 454 | ! 455 | contains 456 | 457 | ! ------------ 458 | ! Platform API 459 | ! ------------ 460 | 461 | ! clGetPlatformIDs 462 | integer(c_int32_t) function clGetPlatformIDs(num_entries, & 463 | platforms, num_platforms) & 464 | BIND(C, NAME='clGetPlatformIDs') 465 | USE ISO_C_BINDING 466 | 467 | integer(c_int32_t), value, intent(in) :: num_entries 468 | type(c_ptr), value, intent(in) :: platforms 469 | integer(c_int32_t), intent(out) :: num_platforms 470 | end function 471 | 472 | ! clGetPlatformInfo 473 | integer(c_int32_t) function clGetPlatformInfo(platform, param_name, & 474 | param_value_size, param_value, param_value_size_ret) & 475 | BIND(C, NAME='clGetPlatformInfo') 476 | USE ISO_C_BINDING 477 | 478 | integer(c_intptr_t), value, intent(in) :: platform 479 | integer(c_int32_t), value, intent(in) :: param_name 480 | integer(c_size_t), value, intent(in) :: param_value_size 481 | type(c_ptr), value, intent(in) :: param_value 482 | integer(c_size_t), intent(out) :: param_value_size_ret 483 | end function 484 | 485 | ! ---------- 486 | ! Device API 487 | ! ---------- 488 | 489 | ! clGetDeviceIDs 490 | integer(c_int32_t) function clGetDeviceIDs(platform, & 491 | device_type, & 492 | num_entries, & 493 | devices, & 494 | num_devices) & 495 | BIND(C, NAME='clGetDeviceIDs') 496 | USE ISO_C_BINDING 497 | 498 | ! Define parameters. 499 | integer(c_intptr_t), value :: platform 500 | integer(c_int64_t), value :: device_type 501 | integer(c_int32_t), value :: num_entries 502 | type(c_ptr), value :: devices 503 | integer(c_int32_t), intent(out) :: num_devices 504 | 505 | end function 506 | 507 | ! clGetDeviceInfo 508 | integer(c_int) function clGetDeviceInfo(device, & 509 | param_name, & 510 | param_value_size, & 511 | param_value, & 512 | param_value_size_ret) & 513 | BIND(C, NAME='clGetDeviceInfo') 514 | USE ISO_C_BINDING 515 | 516 | ! Define parameters. 517 | integer(c_intptr_t), value :: device 518 | integer(c_int32_t), value :: param_name 519 | integer(c_size_t), value :: param_value_size 520 | type(c_ptr), value :: param_value 521 | integer(c_size_t), intent(out) :: param_value_size_ret 522 | 523 | end function 524 | 525 | ! clCreateSubDevices 526 | integer(c_int32_t) function clCreateSubDevices(in_device, & 527 | properties, & 528 | num_devices, & 529 | out_devices, & 530 | num_devices_ret) & 531 | BIND(C, NAME='clCreateSubDevices') 532 | USE ISO_C_BINDING 533 | 534 | ! Define parameters. 535 | integer(c_intptr_t), value :: in_device 536 | type(c_ptr), value :: properties 537 | integer(c_int32_t), value :: num_devices 538 | type(c_ptr), value :: out_devices 539 | integer(c_int32_t), intent(out) :: num_devices_ret 540 | 541 | end function 542 | 543 | ! clRetainDevice 544 | integer(c_int32_t) function clRetainDevice(device) & 545 | BIND(C, NAME='clRetainDevice') 546 | USE ISO_C_BINDING 547 | 548 | ! Define parameters. 549 | integer(c_intptr_t), value :: device 550 | end function 551 | 552 | ! clReleaseDevice 553 | integer(c_int32_t) function clReleaseDevice(device) & 554 | BIND(C, NAME='clReleaseDevice') 555 | USE ISO_C_BINDING 556 | 557 | ! Define parameters. 558 | integer(c_intptr_t), value :: device 559 | end function 560 | 561 | ! ------------ 562 | ! Context APIs 563 | ! ------------ 564 | 565 | ! clCreateContext 566 | integer(c_intptr_t) function clCreateContext(properties, & 567 | num_devices, & 568 | devices, & 569 | pfn_notify, & 570 | user_data, & 571 | errcode_ret) & 572 | BIND(C, NAME='clCreateContext') 573 | USE ISO_C_BINDING 574 | 575 | ! Define parameters. 576 | type(c_ptr), value :: properties 577 | integer(c_int32_t), value :: num_devices 578 | type(c_ptr), value :: devices 579 | type(c_funptr), value :: pfn_notify 580 | type(c_ptr), value :: user_data 581 | integer(c_int32_t), intent(out) :: errcode_ret 582 | 583 | end function 584 | 585 | ! clCreateContextFromType 586 | integer(c_intptr_t) function clCreateContextFromType(properties, & 587 | device_type, & 588 | pfn_notify, & 589 | user_data, & 590 | errcode_ret) & 591 | BIND(C, NAME='clCreateContextFromType') 592 | USE ISO_C_BINDING 593 | 594 | ! Define parameters. 595 | type(c_ptr), value :: properties 596 | integer(c_int64_t), value :: device_type 597 | type(c_funptr), value :: pfn_notify 598 | type(c_ptr), value :: user_data 599 | integer(c_int32_t), intent(out) :: errcode_ret 600 | 601 | end function 602 | 603 | ! clRetainContext 604 | integer(c_int32_t) function clRetainContext(context) & 605 | BIND(C, NAME='clRetainContext') 606 | USE ISO_C_BINDING 607 | 608 | ! Define parameters. 609 | integer(c_intptr_t), value :: context 610 | 611 | end function 612 | 613 | ! clReleaseContext 614 | integer(c_int32_t) function clReleaseContext(context) & 615 | BIND(C, NAME='clReleaseContext') 616 | USE ISO_C_BINDING 617 | 618 | ! Define parameters. 619 | integer(c_intptr_t), value :: context 620 | 621 | end function 622 | 623 | ! clGetContextInfo 624 | integer(c_int32_t) function clGetContextInfo(context, & 625 | param_name, & 626 | param_value_size, & 627 | param_value, & 628 | param_value_size_ret) & 629 | BIND(C, NAME='clGetContextInfo') 630 | USE ISO_C_BINDING 631 | 632 | ! Define parameters. 633 | integer(c_intptr_t), value :: context 634 | integer(c_int32_t), value :: param_name 635 | integer(c_size_t), value :: param_value_size 636 | type(c_ptr), value :: param_value 637 | integer(c_size_t), intent(out) :: param_value_size_ret 638 | 639 | end function 640 | 641 | ! ------------------ 642 | ! Command Queue APIs 643 | ! ------------------ 644 | 645 | ! clCreateCommandQueue 646 | integer(c_intptr_t) function clCreateCommandQueue(context, & 647 | device, & 648 | properties, & 649 | errcode_ret) & 650 | BIND(C, NAME='clCreateCommandQueue') 651 | USE ISO_C_BINDING 652 | 653 | ! Define parameters. 654 | integer(c_intptr_t), value :: context 655 | integer(c_intptr_t), value :: device 656 | integer(c_int64_t), value :: properties 657 | integer(c_int32_t), intent(out) :: errcode_ret 658 | 659 | end function 660 | 661 | ! clRetainCommandQueue 662 | integer(c_int32_t) function clRetainCommandQueue(command_queue) & 663 | BIND(C, NAME='clRetainCommandQueue') 664 | USE ISO_C_BINDING 665 | 666 | ! Define parameters. 667 | integer(c_intptr_t), value :: command_queue 668 | 669 | end function 670 | 671 | ! clReleaseCommandQueue 672 | integer(c_int32_t) function clReleaseCommandQueue(command_queue) & 673 | BIND(C, NAME='clReleaseCommandQueue') 674 | USE ISO_C_BINDING 675 | 676 | ! Define parameters. 677 | integer(c_intptr_t), value :: command_queue 678 | 679 | end function 680 | 681 | ! clGetCommandQueueInfo 682 | integer(c_int32_t) function clGetCommandQueueInfo(command_queue, & 683 | param_name, & 684 | param_value_size, & 685 | param_value, & 686 | param_value_size_ret) & 687 | BIND(C, NAME='clGetCommandQueueInfo') 688 | USE ISO_C_BINDING 689 | 690 | ! Define parameters. 691 | integer(c_intptr_t), value :: command_queue 692 | integer(c_int32_t), value :: param_name 693 | integer(c_size_t), value :: param_value_size 694 | type(c_ptr), value :: param_value 695 | integer(c_size_t), intent(out) :: param_value_size_ret 696 | 697 | end function 698 | 699 | ! ------------------ 700 | ! Memory Object APIs 701 | ! ------------------ 702 | 703 | ! clCreateBuffer 704 | integer(c_intptr_t) function clCreateBuffer(context, & 705 | flags, & 706 | sizeb, & 707 | host_ptr, & 708 | errcode_ret) & 709 | BIND(C, NAME='clCreateBuffer') 710 | USE ISO_C_BINDING 711 | 712 | ! Define parameters. 713 | integer(c_intptr_t), value :: context 714 | integer(c_int64_t), value :: flags 715 | integer(c_size_t), value :: sizeb 716 | type(c_ptr), value :: host_ptr 717 | integer(c_int32_t), intent(out) :: errcode_ret 718 | 719 | end function 720 | 721 | ! clCreateSubBuffer 722 | integer(c_intptr_t) function clCreateSubBuffer(buffer, & 723 | flags, & 724 | buffer_create_type, & 725 | buffer_create_info, & 726 | errcode_ret) & 727 | BIND(C, NAME='clCreateSubBuffer') 728 | USE ISO_C_BINDING 729 | 730 | ! Define parameters. 731 | integer(c_intptr_t), value :: buffer 732 | integer(c_int64_t), value :: flags 733 | integer(c_int32_t), value :: buffer_create_type 734 | type(c_ptr), value :: buffer_create_info 735 | integer(c_int32_t), intent(out) :: errcode_ret 736 | 737 | end function 738 | 739 | ! clCreateImage 740 | integer(c_intptr_t) function clCreateImage(context, & 741 | flags, & 742 | image_format, & 743 | image_desc, & 744 | host_ptr, & 745 | errcode_ret) & 746 | BIND(C, NAME='clCreateImage') 747 | USE ISO_C_BINDING 748 | 749 | ! Define parameters. 750 | integer(c_intptr_t), value :: context 751 | integer(c_int64_t), value :: flags 752 | type(cl_image_format) :: image_format 753 | type(cl_image_desc) :: image_desc 754 | type(c_ptr), value :: host_ptr 755 | integer(c_int32_t), intent(out) :: errcode_ret 756 | 757 | end function 758 | 759 | ! clRetainMemObject 760 | integer(c_int32_t) function clRetainMemObject(mem_obj) & 761 | BIND(C, NAME='clRetainMemObject') 762 | 763 | ! Define parameters. 764 | integer(c_intptr_t), value :: mem_obj 765 | 766 | end function 767 | 768 | ! clReleaseMemObject 769 | integer(c_int32_t) function clReleaseMemObject(mem_obj) & 770 | BIND(C, NAME='clReleaseMemObject') 771 | 772 | ! Define parameters. 773 | integer(c_intptr_t), value :: mem_obj 774 | 775 | end function 776 | 777 | ! clGetSupportedImageFormats 778 | integer(c_int32_t) function clGetSupportedImageFormats(context, & 779 | flags, & 780 | image_type, & 781 | num_entries, & 782 | image_formats, & 783 | num_image_formats) & 784 | BIND(C, NAME='clGetSupportedImageFormats') 785 | 786 | ! Define parameters. 787 | integer(c_intptr_t), value :: context 788 | integer(c_int64_t), value :: flags 789 | integer(c_int32_t), value :: image_type 790 | integer(c_int32_t), value :: num_entries 791 | type(c_ptr), value :: image_formats 792 | integer(c_int32_t), intent(out) :: num_image_formats 793 | 794 | end function 795 | 796 | ! clGetMemObjectInfo 797 | integer(c_int32_t) function clGetMemObjectInfo(memobj, & 798 | param_name, & 799 | param_value_size, & 800 | param_value, & 801 | param_value_size_ret) & 802 | BIND(C, NAME='clGetMemObjectInfo') 803 | 804 | ! Define parameters. 805 | integer(c_intptr_t), value :: memobj 806 | integer(c_int32_t), value :: param_name 807 | integer(c_size_t), value :: param_value_size 808 | type(c_ptr), value :: param_value 809 | integer(c_size_t), intent(out) :: param_value_size_ret 810 | 811 | end function 812 | 813 | ! clGetImageInfo 814 | integer(c_int32_t) function clGetImageInfo(image, & 815 | param_name, & 816 | param_value_size, & 817 | param_value, & 818 | param_value_size_ret) & 819 | BIND(C, NAME='clGetImageInfo') 820 | 821 | ! Define parameters. 822 | integer(c_intptr_t), value :: image 823 | integer(c_int32_t), value :: param_name 824 | integer(c_size_t), value :: param_value_size 825 | type(c_ptr), value :: param_value 826 | integer(c_size_t), intent(out) :: param_value_size_ret 827 | 828 | end function 829 | 830 | ! clSetMemObjectDestructorCallback 831 | integer(c_int32_t) function clSetMemObjectDestructorCallback(memobj, & 832 | pfn_notify, & 833 | user_data) & 834 | BIND(C, NAME='clSetMemObjectDestructorCallback') 835 | 836 | ! Define parameters. 837 | integer(c_intptr_t), value :: memobj 838 | type(c_funptr), value :: pfn_notify 839 | type(c_ptr), value :: user_data 840 | 841 | end function 842 | 843 | ! ------------ 844 | ! Sampler APIs 845 | ! ------------ 846 | 847 | ! clCreateSampler 848 | integer(c_intptr_t) function clCreateSampler(context, & 849 | normalized_coords, & 850 | addressing_mode, & 851 | filter_mode, & 852 | errcode_ret) & 853 | BIND(C, NAME='clCreateSampler') 854 | 855 | ! Define parameters. 856 | integer(c_intptr_t), value :: context 857 | integer(c_int32_t), value :: normalized_coords 858 | integer(c_int32_t), value :: addressing_mode 859 | integer(c_int32_t), value :: filter_mode 860 | integer(c_int32_t), intent(out) :: errcode_ret 861 | 862 | end function 863 | 864 | ! clRetainSampler 865 | integer(c_int32_t) function clRetainSampler(sampler) & 866 | BIND(C, NAME='clRetainSampler') 867 | 868 | ! Define parameters. 869 | integer(c_intptr_t), value :: sampler 870 | 871 | end function 872 | 873 | ! clReleaseSampler 874 | integer(c_int32_t) function clReleaseSampler(sampler) & 875 | BIND(C, NAME='clReleaseSampler') 876 | 877 | ! Define parameters. 878 | integer(c_intptr_t), value :: sampler 879 | 880 | end function 881 | 882 | ! clGetSamplerInfo 883 | integer(c_int32_t) function clGetSamplerInfo(sampler, & 884 | param_name, & 885 | param_value_size, & 886 | param_value, & 887 | param_value_size_ret) & 888 | BIND(C, NAME='clGetSamplerInfo') 889 | 890 | ! Define parameters. 891 | integer(c_intptr_t), value :: sampler 892 | integer(c_int32_t), value :: param_name 893 | integer(c_size_t), value :: param_value_size 894 | type(c_ptr), value :: param_value 895 | integer(c_size_t), intent(out) :: param_value_size_ret 896 | 897 | end function 898 | 899 | ! ------------------- 900 | ! Program Object APIs 901 | ! ------------------- 902 | 903 | ! clCreateProgramWithSource 904 | integer(c_intptr_t) function clCreateProgramWithSource(context, & 905 | count, & 906 | strings, & 907 | lengths, & 908 | errcode_ret) & 909 | BIND(C, NAME='clCreateProgramWithSource') 910 | 911 | ! Define parameters. 912 | integer(c_intptr_t), value :: context 913 | integer(c_int32_t), value :: count 914 | type(c_ptr), value :: strings 915 | type(c_ptr), value :: lengths 916 | integer(c_int32_t), intent(out) :: errcode_ret 917 | 918 | end function 919 | 920 | ! clCreateProgramWithBinary 921 | integer(c_intptr_t) function clCreateProgramWithBinary(context, & 922 | num_devices, & 923 | device_list, & 924 | lengths, & 925 | binaries, & 926 | binary_status, & 927 | errcode_ret) & 928 | BIND(C, NAME='clCreateProgramWithBinary') 929 | 930 | ! Define parameters. 931 | integer(c_intptr_t), value :: context 932 | integer(c_int32_t), value :: num_devices 933 | type(c_ptr), value :: device_list 934 | type(c_ptr), value :: lengths 935 | type(c_ptr), value :: binaries 936 | type(c_ptr), value :: binary_status 937 | integer(c_int32_t), intent(out) :: errcode_ret 938 | 939 | end function 940 | 941 | ! clCreateProgramWithBuiltInKernels 942 | integer(c_intptr_t) function clCreateProgramWithBuiltInKernels(context, & 943 | num_devices, & 944 | device_list, & 945 | kernel_names, & 946 | errcode_ret) & 947 | BIND(C, NAME='clCreateProgramWithBuiltInKernels') 948 | 949 | ! Define parameters. 950 | integer(c_intptr_t), value :: context 951 | integer(c_int32_t), value :: num_devices 952 | type(c_ptr), value :: device_list 953 | type(c_ptr), value :: kernel_names 954 | integer(c_int32_t), intent(out) :: errcode_ret 955 | 956 | end function 957 | 958 | ! clRetainProgram 959 | integer(c_int32_t) function clRetainProgram(program) & 960 | BIND(C, NAME='clRetainProgram') 961 | 962 | ! Define parameters. 963 | integer(c_intptr_t), value :: program 964 | 965 | end function 966 | 967 | ! clReleaseProgram 968 | integer(c_int32_t) function clReleaseProgram(program) & 969 | BIND(C, NAME='clReleaseProgram') 970 | 971 | ! Define parameters. 972 | integer(c_intptr_t), value :: program 973 | 974 | end function 975 | 976 | ! clBuildProgram 977 | integer(c_int32_t) function clBuildProgram(program, & 978 | num_devices, & 979 | device_list, & 980 | options, & 981 | pfn_notify, & 982 | user_data) & 983 | BIND(C, NAME='clBuildProgram') 984 | 985 | ! Define parameters. 986 | integer(c_intptr_t), value :: program 987 | integer(c_int32_t), value :: num_devices 988 | type(c_ptr), value :: device_list 989 | type(c_ptr), value :: options 990 | type(c_funptr), value :: pfn_notify 991 | type(c_ptr), value :: user_data 992 | 993 | end function 994 | 995 | ! clCompileProgram 996 | integer(c_int32_t) function clCompileProgram(program, & 997 | num_devices, & 998 | device_list, & 999 | options, & 1000 | num_input_headers, & 1001 | input_headers, & 1002 | header_include_names, & 1003 | pfn_notify, & 1004 | user_data) & 1005 | BIND(C, NAME='clCompileProgram') 1006 | 1007 | ! Define parameters. 1008 | integer(c_intptr_t), value :: program 1009 | integer(c_int32_t), value :: num_devices 1010 | type(c_ptr), value :: device_list 1011 | type(c_ptr), value :: options 1012 | integer(c_int32_t), value :: num_input_headers 1013 | type(c_ptr), value :: input_headers 1014 | type(c_ptr), value :: header_include_names 1015 | type(c_funptr), value :: pfn_notify 1016 | type(c_ptr), value :: user_data 1017 | 1018 | end function 1019 | 1020 | ! clLinkProgram 1021 | integer(c_intptr_t) function clLinkProgram(context, & 1022 | num_devices, & 1023 | device_list, & 1024 | options, & 1025 | num_input_programs, & 1026 | input_programs, & 1027 | pfn_notify, & 1028 | user_data, & 1029 | errcode_ret) & 1030 | BIND(C, NAME='clLinkProgram') 1031 | 1032 | ! Define parameters. 1033 | integer(c_intptr_t), value :: context 1034 | integer(c_int32_t), value :: num_devices 1035 | type(c_ptr), value :: device_list 1036 | type(c_ptr), value :: options 1037 | integer(c_int32_t), value :: num_input_programs 1038 | type(c_ptr), value :: input_programs 1039 | type(c_funptr), value :: pfn_notify 1040 | type(c_ptr), value :: user_data 1041 | integer(c_int32_t), intent(out) :: errcode_ret 1042 | 1043 | end function 1044 | 1045 | ! clUnloadPlatformCompiler 1046 | integer(c_int32_t) function clUnloadPlatformCompiler(platform) & 1047 | BIND(C, NAME='clUnloadPlatformCompiler') 1048 | 1049 | ! Define parameters. 1050 | integer(c_intptr_t), value :: platform 1051 | 1052 | end function 1053 | 1054 | ! clGetProgramInfo 1055 | integer(c_int32_t) function clGetProgramInfo(program, & 1056 | param_name, & 1057 | param_value_size, & 1058 | param_value, & 1059 | param_value_size_ret) & 1060 | BIND(C, NAME='clGetProgramInfo') 1061 | 1062 | ! Define parameters. 1063 | integer(c_intptr_t), value :: program 1064 | integer(c_int32_t), value :: param_name 1065 | integer(c_size_t), value :: param_value_size 1066 | type(c_ptr), value :: param_value 1067 | integer(c_size_t), intent(out) :: param_value_size_ret 1068 | 1069 | end function 1070 | 1071 | ! clGetProgramBuildInfo 1072 | integer(c_int32_t) function clGetProgramBuildInfo(program, & 1073 | device, & 1074 | param_name, & 1075 | param_value_size, & 1076 | param_value, & 1077 | param_value_size_ret) & 1078 | BIND(C, NAME='clGetProgramBuildInfo') 1079 | 1080 | ! Define parameters. 1081 | integer(c_intptr_t), value :: program 1082 | integer(c_intptr_t), value :: device 1083 | integer(c_int32_t), value :: param_name 1084 | integer(c_size_t), value :: param_value_size 1085 | type(c_ptr), value :: param_value 1086 | integer(c_size_t), intent(out) :: param_value_size_ret 1087 | 1088 | end function 1089 | 1090 | ! ------------------ 1091 | ! Kernel Object APIs 1092 | ! ------------------ 1093 | 1094 | ! clCreateKernel 1095 | integer(c_intptr_t) function clCreateKernel(program, & 1096 | kernel_name, & 1097 | errcode_ret) & 1098 | BIND(C, NAME='clCreateKernel') 1099 | 1100 | ! Define parameters. 1101 | integer(c_intptr_t), value :: program 1102 | type(c_ptr), value :: kernel_name 1103 | integer(c_int32_t), intent(out) :: errcode_ret 1104 | 1105 | end function 1106 | 1107 | ! clCreateKernelsInProgram 1108 | integer(c_int32_t) function clCreateKernelsInProgram(program, & 1109 | num_kernels, & 1110 | kernels, & 1111 | num_kernels_ret) & 1112 | BIND(C, NAME='clCreateKernelsInProgram') 1113 | 1114 | ! Define parameters. 1115 | integer(c_intptr_t), value :: program 1116 | integer(c_int32_t), value :: num_kernels 1117 | type(c_ptr), value :: kernels 1118 | integer(c_int32_t), intent(out) :: num_kernels_ret 1119 | 1120 | end function 1121 | 1122 | ! clRetainKernel 1123 | integer(c_int32_t) function clRetainKernel(kernel) & 1124 | BIND(C, NAME='clRetainKernel') 1125 | 1126 | ! Define parameters. 1127 | integer(c_intptr_t), value :: kernel 1128 | 1129 | end function 1130 | 1131 | ! clReleaseKernel 1132 | integer(c_int32_t) function clReleaseKernel(kernel) & 1133 | BIND(C, NAME='clReleaseKernel') 1134 | 1135 | ! Define parameters. 1136 | integer(c_intptr_t), value :: kernel 1137 | 1138 | end function 1139 | 1140 | ! clSetKernelArg 1141 | integer(c_int32_t) function clSetKernelArg(kernel, & 1142 | arg_index, & 1143 | arg_size, & 1144 | arg_value) & 1145 | BIND(C, NAME='clSetKernelArg') 1146 | 1147 | ! Define parameters. 1148 | integer(c_intptr_t), value :: kernel 1149 | integer(c_int32_t), value :: arg_index 1150 | integer(c_size_t), value :: arg_size 1151 | type(c_ptr), value :: arg_value 1152 | 1153 | end function 1154 | 1155 | ! clGetKernelInfo 1156 | integer(c_int32_t) function clGetKernelInfo(kernel, & 1157 | param_name, & 1158 | param_value_size, & 1159 | param_value, & 1160 | param_value_size_ret) & 1161 | BIND(C, NAME='clGetKernelInfo') 1162 | 1163 | ! Define parameters. 1164 | integer(c_intptr_t), value :: kernel 1165 | integer(c_int32_t), value :: param_name 1166 | integer(c_size_t), value :: param_value_size 1167 | type(c_ptr), value :: param_value 1168 | integer(c_size_t), intent(out) :: param_value_size_ret 1169 | 1170 | end function 1171 | 1172 | ! clGetKernelArgInfo 1173 | integer(c_int32_t) function clGetKernelArgInfo(kernel, & 1174 | arg_index, & 1175 | param_name, & 1176 | param_value_size, & 1177 | param_value, & 1178 | param_value_size_ret) & 1179 | BIND(C, NAME='clGetKernelArgInfo') 1180 | 1181 | ! Define parameters. 1182 | integer(c_intptr_t), value :: kernel 1183 | integer(c_int32_t), value :: arg_index 1184 | integer(c_int32_t), value :: param_name 1185 | integer(c_size_t), value :: param_value_size 1186 | type(c_ptr), value :: param_value 1187 | integer(c_size_t), intent(out) :: param_value_size_ret 1188 | 1189 | end function 1190 | 1191 | ! clGetKernelWorkGroupInfo 1192 | integer(c_int32_t) function clGetKernelWorkGroupInfo(kernel, & 1193 | device, & 1194 | param_name, & 1195 | param_value_size, & 1196 | param_value, & 1197 | param_value_size_ret) & 1198 | BIND(C, NAME='clGetKernelWorkGroupInfo') 1199 | 1200 | ! Define parameters. 1201 | integer(c_intptr_t), value :: kernel 1202 | integer(c_intptr_t), value :: device 1203 | integer(c_int32_t), value :: param_name 1204 | integer(c_size_t), value :: param_value_size 1205 | type(c_ptr), value :: param_value 1206 | integer(c_size_t), intent(out) :: param_value_size_ret 1207 | 1208 | end function 1209 | 1210 | ! ----------------- 1211 | ! Event Object APIs 1212 | ! ----------------- 1213 | 1214 | ! clWaitForEvents 1215 | integer(c_int32_t) function clWaitForEvents(num_events, & 1216 | event_list) & 1217 | BIND(C, NAME='clWaitForEvents') 1218 | 1219 | ! Define parameters. 1220 | integer(c_int32_t), value :: num_events 1221 | type(c_ptr), value :: event_list 1222 | 1223 | end function 1224 | 1225 | ! clGetEventInfo 1226 | integer(c_int32_t) function clGetEventInfo(event, & 1227 | param_name, & 1228 | param_value_size, & 1229 | param_value, & 1230 | param_value_size_ret) & 1231 | BIND(C, NAME='clGetEventInfo') 1232 | 1233 | ! Define parameters. 1234 | integer(c_intptr_t), value :: event 1235 | integer(c_int32_t), value :: param_name 1236 | integer(c_size_t), value :: param_value_size 1237 | type(c_ptr), value :: param_value 1238 | integer(c_size_t), intent(out) :: param_value_size_ret 1239 | 1240 | end function 1241 | 1242 | ! clCreateUserEvent 1243 | integer(c_intptr_t) function clCreateUserEvent(context, & 1244 | errcode_ret) & 1245 | BIND(C, NAME='clCreateUserEvent') 1246 | 1247 | ! Define parameters. 1248 | integer(c_int32_t), value :: context 1249 | integer(c_int32_t), intent(out) :: errcode_ret 1250 | 1251 | end function 1252 | 1253 | ! clRetainEvent 1254 | integer(c_int32_t) function clRetainEvent(event) & 1255 | BIND(C, NAME='clRetainEvent') 1256 | 1257 | ! Define parameters. 1258 | integer(c_intptr_t), value :: event 1259 | 1260 | end function 1261 | 1262 | ! clReleaseEvent 1263 | integer(c_int32_t) function clReleaseEvent(event) & 1264 | BIND(C, NAME='clReleaseEvent') 1265 | 1266 | ! Define parameters. 1267 | integer(c_intptr_t), value :: event 1268 | 1269 | end function 1270 | 1271 | ! clSetUserEventStatus 1272 | integer(c_int32_t) function clSetUserEventStatus(event, & 1273 | execution_status) & 1274 | BIND(C, NAME='clSetUserEventStatus') 1275 | 1276 | ! Define parameters. 1277 | integer(c_intptr_t), value :: event 1278 | integer(c_int32_t), value :: execution_status 1279 | 1280 | end function 1281 | 1282 | ! clSetEventCallback 1283 | integer(c_int32_t) function clSetEventCallback(event, & 1284 | command_exec_callback_type, & 1285 | pfn_notify, & 1286 | user_data) & 1287 | BIND(C, NAME='clSetEventCallback') 1288 | 1289 | ! Define parameters. 1290 | integer(c_intptr_t), value :: event 1291 | integer(c_int32_t), value :: command_exec_callback_type 1292 | type(c_funptr), value :: pfn_notify 1293 | type(c_ptr), value :: user_data 1294 | 1295 | end function 1296 | 1297 | ! -------------- 1298 | ! Profiling APIs 1299 | ! -------------- 1300 | 1301 | ! clGetEventProfilingInfo 1302 | integer(c_int32_t) function clGetEventProfilingInfo(event, & 1303 | param_name, & 1304 | param_value_size, & 1305 | param_value, & 1306 | param_value_size_ret) & 1307 | BIND(C, NAME='clGetEventProfilingInfo') 1308 | 1309 | ! Define parameters. 1310 | integer(c_intptr_t), value :: event 1311 | integer(c_int32_t), value :: param_name 1312 | integer(c_size_t), value :: param_value_size 1313 | type(c_ptr), value :: param_value 1314 | integer(c_size_t), intent(out) :: param_value_size_ret 1315 | 1316 | end function 1317 | 1318 | ! --------------------- 1319 | ! Flush and Finish APIs 1320 | ! --------------------- 1321 | 1322 | ! clFlush 1323 | integer(c_int32_t) function clFlush(command_queue) & 1324 | BIND(C, NAME='clFlush') 1325 | 1326 | ! Define parameters. 1327 | integer(c_intptr_t), value :: command_queue 1328 | 1329 | end function 1330 | 1331 | ! clFinish 1332 | integer(c_int32_t) function clFinish(command_queue) & 1333 | BIND(C, NAME='clFinish') 1334 | 1335 | ! Define parameters. 1336 | integer(c_intptr_t), value :: command_queue 1337 | 1338 | end function 1339 | 1340 | ! ---------------------- 1341 | ! Enqueued Commands APIs 1342 | ! ---------------------- 1343 | 1344 | ! clEnqueueReadBuffer 1345 | integer(c_int32_t) function clEnqueueReadBuffer(command_queue, & 1346 | buffer, & 1347 | blocking_read, & 1348 | offset, & 1349 | size, & 1350 | ptr, & 1351 | num_events_in_wait_list, & 1352 | event_wait_list, & 1353 | event) & 1354 | BIND(C, NAME='clEnqueueReadBuffer') 1355 | 1356 | ! Define parameters. 1357 | integer(c_intptr_t), value :: command_queue 1358 | integer(c_intptr_t), value :: buffer 1359 | integer(c_int32_t), value :: blocking_read 1360 | integer(c_size_t), value :: offset 1361 | integer(c_size_t), value :: size 1362 | type(c_ptr), value :: ptr 1363 | integer(c_int32_t), value :: num_events_in_wait_list 1364 | type(c_ptr), value :: event_wait_list 1365 | type(c_ptr), value :: event 1366 | 1367 | end function 1368 | 1369 | ! clEnqueueReadBufferRect 1370 | integer(c_int32_t) function clEnqueueReadBufferRect(command_queue, & 1371 | buffer, & 1372 | blocking_read, & 1373 | buffer_offset, & 1374 | host_offset, & 1375 | region, & 1376 | buffer_row_pitch, & 1377 | buffer_slice_pitch, & 1378 | host_row_pitch, & 1379 | host_slice_pitch, & 1380 | ptr, & 1381 | num_events_in_wait_list, & 1382 | event_wait_list, & 1383 | event) & 1384 | BIND(C, NAME='clEnqueueReadBufferRect') 1385 | 1386 | ! Define parameters. 1387 | integer(c_intptr_t), value :: command_queue 1388 | 1389 | integer(c_intptr_t), value :: buffer 1390 | integer(c_int32_t), value :: blocking_read 1391 | type(c_ptr), value :: buffer_offset 1392 | type(c_ptr), value :: host_offset 1393 | type(c_ptr), value :: region 1394 | integer(c_size_t), value :: buffer_row_pitch 1395 | integer(c_size_t), value :: buffer_slice_pitch 1396 | integer(c_size_t), value :: host_row_pitch 1397 | integer(c_size_t), value :: host_slice_pitch 1398 | type(c_ptr), value :: ptr 1399 | integer(c_int32_t), value :: num_events_in_wait_list 1400 | type(c_ptr), value :: event_wait_list 1401 | type(c_ptr), value :: event 1402 | 1403 | end function 1404 | 1405 | ! clEnqueueWriteBuffer 1406 | integer(c_int32_t) function clEnqueueWriteBuffer(command_queue, & 1407 | buffer, & 1408 | blocking_write, & 1409 | offset, & 1410 | size, & 1411 | ptr, & 1412 | num_events_in_wait_list, & 1413 | event_wait_list, & 1414 | event) & 1415 | BIND(C, NAME='clEnqueueWriteBuffer') 1416 | 1417 | ! Define parameters. 1418 | integer(c_intptr_t), value :: command_queue 1419 | integer(c_intptr_t), value :: buffer 1420 | integer(c_int32_t), value :: blocking_write 1421 | integer(c_size_t), value :: offset 1422 | integer(c_size_t), value :: size 1423 | type(c_ptr), value :: ptr 1424 | integer(c_int32_t), value :: num_events_in_wait_list 1425 | type(c_ptr), value :: event_wait_list 1426 | type(c_ptr), value :: event 1427 | 1428 | end function 1429 | 1430 | ! clEnqueueWriteBufferRect 1431 | integer(c_int32_t) function clEnqueueWriteBufferRect(command_queue, & 1432 | buffer, & 1433 | blocking_write, & 1434 | buffer_offset, & 1435 | host_offset, & 1436 | region, & 1437 | buffer_row_pitch, & 1438 | buffer_slice_pitch, & 1439 | host_row_pitch, & 1440 | host_slice_pitch, & 1441 | ptr, & 1442 | num_events_in_wait_list, & 1443 | event_wait_list, & 1444 | event) & 1445 | BIND(C, NAME='clEnqueueWriteBufferRect') 1446 | 1447 | ! Define parameters. 1448 | integer(c_intptr_t), value :: command_queue 1449 | integer(c_intptr_t), value :: buffer 1450 | integer(c_int32_t), value :: blocking_write 1451 | type(c_ptr), value :: buffer_offset 1452 | type(c_ptr), value :: host_offset 1453 | type(c_ptr), value :: region 1454 | integer(c_size_t), value :: buffer_row_pitch 1455 | integer(c_size_t), value :: buffer_slice_pitch 1456 | integer(c_size_t), value :: host_row_pitch 1457 | integer(c_size_t), value :: host_slice_pitch 1458 | type(c_ptr), value :: ptr 1459 | integer(c_int32_t), value :: num_events_in_wait_list 1460 | type(c_ptr), value :: event_wait_list 1461 | type(c_ptr), value :: event 1462 | 1463 | end function 1464 | 1465 | ! clEnqueueFillBuffer 1466 | integer(c_int32_t) function clEnqueueFillBuffer(command_queue, & 1467 | buffer, & 1468 | pattern, & 1469 | pattern_size, & 1470 | offset, & 1471 | size, & 1472 | num_events_in_wait_list, & 1473 | event_wait_list, & 1474 | event) & 1475 | BIND(C, NAME='clEnqueueFillBuffer') 1476 | 1477 | ! Define parameters. 1478 | integer(c_intptr_t), value :: command_queue 1479 | integer(c_intptr_t), value :: buffer 1480 | type(c_ptr), value :: pattern 1481 | integer(c_size_t), value :: pattern_size 1482 | integer(c_size_t), value :: offset 1483 | integer(c_size_t), value :: size 1484 | integer(c_int32_t), value :: num_events_in_wait_list 1485 | type(c_ptr), value :: event_wait_list 1486 | type(c_ptr), value :: event 1487 | 1488 | end function 1489 | 1490 | ! clEnqueueCopyBuffer 1491 | integer(c_int32_t) function clEnqueueCopyBuffer(command_queue, & 1492 | src_buffer, & 1493 | dst_buffer, & 1494 | src_offset, & 1495 | dst_offset, & 1496 | size, & 1497 | num_events_in_wait_list, & 1498 | event_wait_list, & 1499 | event) & 1500 | BIND(C, NAME='clEnqueueCopyBuffer') 1501 | 1502 | ! Define parameters. 1503 | integer(c_intptr_t), value :: command_queue 1504 | integer(c_intptr_t), value :: src_buffer 1505 | integer(c_intptr_t), value :: dst_buffer 1506 | integer(c_size_t), value :: src_offset 1507 | integer(c_size_t), value :: dst_offset 1508 | integer(c_size_t), value :: size 1509 | integer(c_int32_t), value :: num_events_in_wait_list 1510 | type(c_ptr), value :: event_wait_list 1511 | type(c_ptr), value :: event 1512 | 1513 | end function 1514 | 1515 | ! clEnqueueCopyBufferRect 1516 | integer(c_int32_t) function clEnqueueCopyBufferRect(command_queue, & 1517 | src_buffer, & 1518 | dst_buffer, & 1519 | src_origin, & 1520 | dst_origin, & 1521 | region, & 1522 | src_row_pitch, & 1523 | src_slice_pitch, & 1524 | dst_row_pitch, & 1525 | dst_slice_pitch, & 1526 | num_events_in_wait_list, & 1527 | event_wait_list, & 1528 | event) & 1529 | BIND(C, NAME='clEnqueueCopyBufferRect') 1530 | 1531 | ! Define parameters. 1532 | integer(c_intptr_t), value :: command_queue 1533 | integer(c_intptr_t), value :: src_buffer 1534 | integer(c_intptr_t), value :: dst_buffer 1535 | type(c_ptr), value :: src_origin 1536 | type(c_ptr), value :: dst_origin 1537 | type(c_ptr), value :: region 1538 | integer(c_size_t), value :: src_row_pitch 1539 | integer(c_size_t), value :: src_slice_pitch 1540 | integer(c_size_t), value :: dst_row_pitch 1541 | integer(c_size_t), value :: dst_slice_pitch 1542 | integer(c_int32_t), value :: num_events_in_wait_list 1543 | type(c_ptr), value :: event_wait_list 1544 | type(c_ptr), value :: event 1545 | 1546 | end function 1547 | 1548 | ! clEnqueueReadImage 1549 | integer(c_int32_t) function clEnqueueReadImage(command_queue, & 1550 | image, & 1551 | blocking_read, & 1552 | origin, & 1553 | region, & 1554 | row_pitch, & 1555 | slice_pitch, & 1556 | ptr, & 1557 | num_events_in_wait_list, & 1558 | event_wait_list, & 1559 | event) & 1560 | BIND(C, NAME='clEnqueueReadImage') 1561 | 1562 | ! Define parameters. 1563 | integer(c_intptr_t), value :: command_queue 1564 | integer(c_intptr_t), value :: image 1565 | integer(c_int32_t), value :: blocking_read 1566 | type(c_ptr), value :: origin 1567 | type(c_ptr), value :: region 1568 | integer(c_size_t), value :: row_pitch 1569 | integer(c_size_t), value :: slice_pitch 1570 | type(c_ptr), value :: ptr 1571 | integer(c_int32_t), value :: num_events_in_wait_list 1572 | type(c_ptr), value :: event_wait_list 1573 | type(c_ptr), value :: event 1574 | 1575 | end function 1576 | 1577 | ! clEnqueueWriteImage 1578 | integer(c_int32_t) function clEnqueueWriteImage(command_queue, & 1579 | image, & 1580 | blocking_write, & 1581 | origin, & 1582 | region, & 1583 | input_row_pitch, & 1584 | input_slice_pitch, & 1585 | ptr, & 1586 | num_events_in_wait_list, & 1587 | event_wait_list, & 1588 | event) & 1589 | BIND(C, NAME='clEnqueueWriteImage') 1590 | 1591 | ! Define parameters. 1592 | integer(c_intptr_t), value :: command_queue 1593 | integer(c_intptr_t), value :: image 1594 | integer(c_int32_t), value :: blocking_write 1595 | type(c_ptr), value :: origin 1596 | type(c_ptr), value :: region 1597 | integer(c_size_t), value :: input_row_pitch 1598 | integer(c_size_t), value :: input_slice_pitch 1599 | type(c_ptr), value :: ptr 1600 | integer(c_int32_t), value :: num_events_in_wait_list 1601 | type(c_ptr), value :: event_wait_list 1602 | type(c_ptr), value :: event 1603 | 1604 | end function 1605 | 1606 | ! clEnqueueFillImage 1607 | integer(c_int32_t) function clEnqueueFillImage(command_queue, & 1608 | image, & 1609 | fill_color, & 1610 | origin, & 1611 | region, & 1612 | num_events_in_wait_list, & 1613 | event_wait_list, & 1614 | event) & 1615 | BIND(C, NAME='clEnqueueFillImage') 1616 | 1617 | ! Define parameters. 1618 | integer(c_intptr_t), value :: command_queue 1619 | integer(c_intptr_t), value :: image 1620 | type(c_ptr), value :: fill_color 1621 | type(c_ptr), value :: origin 1622 | type(c_ptr), value :: region 1623 | integer(c_int32_t), value :: num_events_in_wait_list 1624 | type(c_ptr), value :: event_wait_list 1625 | type(c_ptr), value :: event 1626 | 1627 | end function 1628 | 1629 | ! clEnqueueCopyImage 1630 | integer(c_int32_t) function clEnqueueCopyImage(command_queue, & 1631 | src_image, & 1632 | dst_image, & 1633 | src_origin, & 1634 | dst_origin, & 1635 | region, & 1636 | num_events_in_wait_list, & 1637 | event_wait_list, & 1638 | event) & 1639 | BIND(C, NAME='clEnqueueCopyImage') 1640 | 1641 | ! Define parameters. 1642 | integer(c_intptr_t), value :: command_queue 1643 | integer(c_intptr_t), value :: src_image 1644 | integer(c_intptr_t), value :: dst_image 1645 | type(c_ptr), value :: src_origin 1646 | type(c_ptr), value :: dst_origin 1647 | type(c_ptr), value :: region 1648 | integer(c_int32_t), value :: num_events_in_wait_list 1649 | type(c_ptr), value :: event_wait_list 1650 | type(c_ptr), value :: event 1651 | 1652 | end function 1653 | 1654 | ! clEnqueueCopyImageToBuffer 1655 | integer(c_int32_t) function clEnqueueCopyImageToBuffer(command_queue, & 1656 | src_image, & 1657 | dst_buffer, & 1658 | src_origin, & 1659 | region, & 1660 | dst_offset, & 1661 | num_events_in_wait_list, & 1662 | event_wait_list, & 1663 | event) & 1664 | BIND(C, NAME='clEnqueueCopyImageToBuffer') 1665 | 1666 | ! Define parameters. 1667 | integer(c_intptr_t), value :: command_queue 1668 | integer(c_intptr_t), value :: src_image 1669 | integer(c_intptr_t), value :: dst_buffer 1670 | type(c_ptr), value :: src_origin 1671 | type(c_ptr), value :: region 1672 | integer(c_size_t), value :: dst_offset 1673 | integer(c_int32_t), value :: num_events_in_wait_list 1674 | type(c_ptr), value :: event_wait_list 1675 | type(c_ptr), value :: event 1676 | 1677 | end function 1678 | 1679 | ! clEnqueueCopyBufferToImage 1680 | integer(c_int32_t) function clEnqueueCopyBufferToImage(command_queue, & 1681 | src_buffer, & 1682 | dst_image, & 1683 | src_offset, & 1684 | dst_origin, & 1685 | region, & 1686 | num_events_in_wait_list, & 1687 | event_wait_list, & 1688 | event) & 1689 | BIND(C, NAME='clEnqueueCopyBufferToImage') 1690 | 1691 | ! Define parameters. 1692 | integer(c_intptr_t), value :: command_queue 1693 | integer(c_intptr_t), value :: src_buffer 1694 | integer(c_intptr_t), value :: dst_image 1695 | integer(c_size_t), value :: src_offset 1696 | type(c_ptr), value :: dst_origin 1697 | type(c_ptr), value :: region 1698 | integer(c_int32_t), value :: num_events_in_wait_list 1699 | type(c_ptr), value :: event_wait_list 1700 | type(c_ptr), value :: event 1701 | 1702 | end function 1703 | 1704 | ! clEnqueueMapBuffer 1705 | type(c_ptr) function clEnqueueMapBuffer(command_queue, & 1706 | buffer, & 1707 | blocking_map, & 1708 | map_flags, & 1709 | offset, & 1710 | size, & 1711 | num_events_in_wait_list, & 1712 | event_wait_list, & 1713 | event, & 1714 | errcode_ret) & 1715 | BIND(C, NAME='clEnqueueMapBuffer') 1716 | 1717 | ! Define parameters. 1718 | integer(c_intptr_t), value :: command_queue 1719 | integer(c_intptr_t), value :: buffer 1720 | integer(c_int32_t), value :: blocking_map 1721 | integer(c_int64_t), value :: map_flags 1722 | integer(c_size_t), value :: offset 1723 | integer(c_size_t), value :: size 1724 | integer(c_int32_t), value :: num_events_in_wait_list 1725 | type(c_ptr), value :: event_wait_list 1726 | type(c_ptr), value :: event 1727 | integer(c_int32_t), intent(out) :: errcode_ret 1728 | 1729 | end function 1730 | 1731 | ! clEnqueueMapImage 1732 | type(c_ptr) function clEnqueueMapImage(command_queue, & 1733 | image, & 1734 | blocking_map, & 1735 | map_flags, & 1736 | origin, & 1737 | region, & 1738 | image_row_pitch, & 1739 | image_slice_pitch, & 1740 | num_events_in_wait_list, & 1741 | event_wait_list, & 1742 | event, & 1743 | errcode_ret) & 1744 | BIND(C, NAME='clEnqueueMapImage') 1745 | 1746 | ! Define parameters. 1747 | integer(c_intptr_t), value :: command_queue 1748 | integer(c_intptr_t), value :: image 1749 | integer(c_int32_t), value :: blocking_map 1750 | integer(c_int64_t), value :: map_flags 1751 | type(c_ptr), value :: origin 1752 | type(c_ptr), value :: region 1753 | integer(c_size_t), intent(out) :: image_row_pitch 1754 | integer(c_size_t), intent(out) :: image_slice_pitch 1755 | integer(c_int32_t), value :: num_events_in_wait_list 1756 | type(c_ptr), value :: event_wait_list 1757 | type(c_ptr), value :: event 1758 | integer(c_int32_t), intent(out) :: errcode_ret 1759 | 1760 | end function 1761 | 1762 | ! clEnqueueUnmapMemObject 1763 | integer(c_int32_t) function clEnqueueUnmapMemObject(command_queue, & 1764 | memobj, & 1765 | mapped_ptr, & 1766 | num_events_in_wait_list, & 1767 | event_wait_list, & 1768 | event) & 1769 | BIND(C, NAME='clEnqueueUnmapMemObject') 1770 | 1771 | ! Define parameters. 1772 | integer(c_intptr_t), value :: command_queue 1773 | integer(c_intptr_t), value :: memobj 1774 | type(c_ptr), value :: mapped_ptr 1775 | integer(c_int32_t), value :: num_events_in_wait_list 1776 | type(c_ptr), value :: event_wait_list 1777 | type(c_ptr), value :: event 1778 | 1779 | end function 1780 | 1781 | ! clEnqueueMigrateMemObjects 1782 | integer(c_int32_t) function clEnqueueMigrateMemObjects(command_queue, & 1783 | num_mem_objects, & 1784 | mem_objects, & 1785 | flags, & 1786 | num_events_in_wait_list, & 1787 | event_wait_list, & 1788 | event) & 1789 | BIND(C, NAME='clEnqueueMigrateMemObjects') 1790 | 1791 | ! Define parameters. 1792 | integer(c_intptr_t), value :: command_queue 1793 | integer(c_int32_t), value :: num_mem_objects 1794 | type(c_ptr), value :: mem_objects 1795 | integer(c_int64_t), value :: flags 1796 | integer(c_int32_t), value :: num_events_in_wait_list 1797 | type(c_ptr), value :: event_wait_list 1798 | type(c_ptr), value :: event 1799 | 1800 | end function 1801 | 1802 | ! clEnqueueNDRangeKernel. 1803 | integer(c_int32_t) function clEnqueueNDRangeKernel(command_queue, & 1804 | kernel, & 1805 | work_dim, & 1806 | global_work_offset, & 1807 | global_work_size, & 1808 | local_work_size, & 1809 | num_events_in_wait_list, & 1810 | event_wait_list, & 1811 | event) & 1812 | BIND(C, NAME='clEnqueueNDRangeKernel') 1813 | 1814 | ! Define parameters. 1815 | integer(c_intptr_t), value :: command_queue 1816 | integer(c_intptr_t), value :: kernel 1817 | integer(c_int32_t), value :: work_dim 1818 | type(c_ptr), value :: global_work_offset 1819 | type(c_ptr), value :: global_work_size 1820 | type(c_ptr), value :: local_work_size 1821 | integer(c_int32_t), value :: num_events_in_wait_list 1822 | type(c_ptr), value :: event_wait_list 1823 | type(c_ptr), value :: event 1824 | 1825 | end function 1826 | 1827 | ! clEnqueueTask 1828 | integer(c_int32_t) function clEnqueueTask(command_queue, & 1829 | kernel, & 1830 | num_events_in_wait_list, & 1831 | event_wait_list, & 1832 | event) & 1833 | BIND(C, NAME='clEnqueueTask') 1834 | 1835 | ! Define parameters. 1836 | integer(c_intptr_t), value :: command_queue 1837 | integer(c_intptr_t), value :: kernel 1838 | integer(c_int32_t), value :: num_events_in_wait_list 1839 | type(c_ptr), value :: event_wait_list 1840 | type(c_ptr), value :: event 1841 | 1842 | end function 1843 | 1844 | ! clEnqueueNativeKernel 1845 | integer(c_int32_t) function clEnqueueNativeKernel(command_queue, & 1846 | user_func, & 1847 | args, & 1848 | cb_args, & 1849 | num_mem_objects, & 1850 | mem_list, & 1851 | args_mem_loc, & 1852 | num_events_in_wait_list, & 1853 | event_wait_list, & 1854 | event) & 1855 | BIND(C, NAME='clEnqueueNativeKernel') 1856 | 1857 | ! Define parameters. 1858 | integer(c_intptr_t), value :: command_queue 1859 | type(c_funptr), value :: user_func 1860 | type(c_ptr), value :: args 1861 | integer(c_size_t), value :: cb_args 1862 | integer(c_int32_t), value :: num_mem_objects 1863 | type(c_ptr), value :: mem_list 1864 | type(c_ptr), value :: args_mem_loc 1865 | integer(c_int32_t), value :: num_events_in_wait_list 1866 | type(c_ptr), value :: event_wait_list 1867 | type(c_ptr), value :: event 1868 | 1869 | end function 1870 | 1871 | ! clEnqueueMarkerWithWaitList 1872 | integer(c_int32_t) function clEnqueueMarkerWithWaitList(command_queue, & 1873 | num_events_in_wait_list, & 1874 | event_wait_list, & 1875 | event) & 1876 | BIND(C, NAME='clEnqueueMarkerWithWaitList') 1877 | 1878 | ! Define parameters. 1879 | integer(c_intptr_t), value :: command_queue 1880 | integer(c_int32_t), value :: num_events_in_wait_list 1881 | type(c_ptr), value :: event_wait_list 1882 | type(c_ptr), value :: event 1883 | 1884 | end function 1885 | 1886 | ! clEnqueueMarkerWithWaitList 1887 | integer(c_int32_t) function clEnqueueBarrierWithWaitList(command_queue, & 1888 | num_events_in_wait_list, & 1889 | event_wait_list, & 1890 | event) & 1891 | BIND(C, NAME='clEnqueueBarrierWithWaitList') 1892 | 1893 | ! Define parameters. 1894 | integer(c_intptr_t), value :: command_queue 1895 | integer(c_int32_t), value :: num_events_in_wait_list 1896 | type(c_ptr), value :: event_wait_list 1897 | type(c_ptr), value :: event 1898 | 1899 | end function 1900 | 1901 | ! clSetPrintfCallback 1902 | integer(c_int32_t) function clSetPrintfCallback(context, & 1903 | pfn_notify, & 1904 | user_data) & 1905 | BIND(C, NAME='clSetPrintfCallback') 1906 | 1907 | ! Define parameters. 1908 | integer(c_intptr_t), value :: context 1909 | type(c_funptr), value :: pfn_notify 1910 | type(c_ptr), value :: user_data 1911 | 1912 | end function 1913 | 1914 | ! ------------------------- 1915 | ! Extension function access 1916 | ! ------------------------- 1917 | type(c_funptr) function clGetExtensionFunctionAddressForPlatform(platform, & 1918 | func_name) & 1919 | BIND(C, NAME='clGetExtensionFunctionAddressForPlatform') 1920 | 1921 | ! Define parameters. 1922 | integer(c_intptr_t), value :: platform 1923 | type(c_ptr), value :: func_name 1924 | 1925 | end function 1926 | 1927 | ! 1928 | !end interface 1929 | ! 1930 | 1931 | end module clfortran 1932 | -------------------------------------------------------------------------------- /examples/basic_device_io.f90: -------------------------------------------------------------------------------- 1 | ! ----------------------------------------------------------------------------- 2 | ! CLFORTRAN - OpenCL bindings module for Fortran. 3 | ! 4 | ! This is an example file that demonstrates using CLFORTRAN to perform basic 5 | ! device I/O with OpenCL API. 6 | ! 7 | ! Last Update: 18 March, 2014 8 | ! 9 | ! ----------------------------------------------------------------------------- 10 | ! 11 | ! Copyright (C) 2013-2014 Company for Advanced Supercomputing Solutions LTD 12 | ! Bosmat 2a St. 13 | ! Shoham 14 | ! Israel 60850 15 | ! http://www.cass-hpc.com 16 | ! 17 | ! Author: Mordechai Butrashvily 18 | ! 19 | ! ----------------------------------------------------------------------------- 20 | ! 21 | ! This program is free software: you can redistribute it and/or modify 22 | ! it under the terms of the GNU Lesser General Public License as published by 23 | ! the Free Software Foundation, either version 3 of the License, or 24 | ! (at your option) any later version. 25 | ! 26 | ! This program is distributed in the hope that it will be useful, 27 | ! but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | ! GNU Lesser General Public License for more details. 30 | ! 31 | ! You should have received a copy of the GNU Lesser General Public License 32 | ! along with this program. If not, see . 33 | ! 34 | ! ----------------------------------------------------------------------------- 35 | 36 | ! Main entry point. 37 | ! 38 | ! Queries available platforms, chooses the first and same for its devices. 39 | ! After selection is made, a context is created with command queue. 40 | ! Next, a Fortran array is copied back & forth and compared for validity. 41 | program create_device_context 42 | use clfortran 43 | use ISO_C_BINDING 44 | implicit none 45 | 46 | ! Variable definitions for OpenCL API and in general. 47 | integer(c_int32_t) :: err 48 | integer(c_size_t) :: zero_size = 0 49 | integer(c_size_t) :: temp_size 50 | integer(c_int) :: num_platforms 51 | integer(c_int) :: num_devices 52 | integer(c_intptr_t), allocatable, target :: platform_ids(:) 53 | integer(c_intptr_t), allocatable, target :: device_ids(:) 54 | 55 | integer(c_intptr_t), target :: ctx_props(3) 56 | integer(c_intptr_t), target :: context 57 | integer(c_int64_t) :: cmd_queue_props 58 | integer(c_intptr_t), target :: cmd_queue 59 | 60 | integer(c_intptr_t), target :: d_buffer 61 | integer(c_size_t) :: d_buffer_offset 62 | real(c_float), allocatable, target :: array1(:, :) 63 | real(c_float), allocatable, target :: array2(:, :) 64 | integer(c_size_t) :: array_size_x 65 | integer(c_size_t) :: array_size_y 66 | 67 | print '(A)', 'OpenCL sample for creating context and queue for GPU device' 68 | 69 | ! Get the number of platforms, prior to allocating an array. 70 | err = clGetPlatformIDs(0, C_NULL_PTR, num_platforms) 71 | if (err /= CL_SUCCESS) then 72 | print *, 'Error quering platforms: ', err 73 | call exit(1) 74 | end if 75 | 76 | if (num_platforms == 0) then 77 | print *, 'No platforms found' 78 | call exit(0) 79 | end if 80 | 81 | ! Allocate an array to hold platform handles. 82 | allocate(platform_ids(num_platforms)) 83 | 84 | ! Get platforms IDs. 85 | err = clGetPlatformIDs(num_platforms, C_LOC(platform_ids), num_platforms) 86 | if (err /= CL_SUCCESS) then 87 | print *, 'Error getting platforms: ', err 88 | call exit(1) 89 | end if 90 | 91 | ! 92 | ! Check number of devices for first platform. 93 | ! 94 | err = clGetDeviceIDs(platform_ids(1), CL_DEVICE_TYPE_GPU, 0, C_NULL_PTR, & 95 | num_devices) 96 | if (err /= CL_SUCCESS) then 97 | print *, 'Error quering devices: ', err 98 | call exit(1) 99 | end if 100 | 101 | if (num_devices == 0) then 102 | print *, 'No GPU devices found' 103 | call exit(0) 104 | end if 105 | 106 | ! Allocate an array to hold device handles. 107 | allocate(device_ids(num_devices)) 108 | 109 | ! Get device IDs. 110 | err = clGetDeviceIDs(platform_ids(1), CL_DEVICE_TYPE_GPU, num_devices, & 111 | C_LOC(device_ids), num_devices) 112 | if (err /= CL_SUCCESS) then 113 | print *, 'Error gettings devices: ', err 114 | call exit(1) 115 | end if 116 | 117 | ! 118 | ! Create a context and a command queue. 119 | ! 120 | 121 | ! Context. 122 | num_devices = 1 123 | ctx_props(1) = CL_CONTEXT_PLATFORM 124 | ctx_props(2) = platform_ids(1) 125 | ctx_props(3) = 0 126 | 127 | context = clCreateContext(C_LOC(ctx_props), num_devices, & 128 | C_LOC(device_ids), C_NULL_FUNPTR, C_NULL_PTR, err) 129 | 130 | if (err /= CL_SUCCESS) then 131 | print *, 'Error creating context: ', err 132 | call exit(1) 133 | end if 134 | 135 | ! Command queue. 136 | cmd_queue_props = 0 137 | cmd_queue = clCreateCommandQueue(context, device_ids(1), cmd_queue_props, err) 138 | 139 | if (err /= CL_SUCCESS) then 140 | print *, 'Error creating command queue: ', err 141 | call exit(1) 142 | end if 143 | 144 | print '(A)', 'Successfuly create OpenCL context and queue for GPU device' 145 | 146 | ! 147 | ! Start OpenCL logic here. 148 | ! 149 | 150 | ! Allocate arrays of size 256x256 (float, 32 bit). 151 | array_size_x = 256 152 | array_size_y = 256 153 | allocate(array1(array_size_x, array_size_y)) 154 | allocate(array2(array_size_x, array_size_y)) 155 | 156 | ! Initialize first array with ones. 157 | array1(:, :) = 1.0 158 | 159 | ! Allocate device buffer. 160 | d_buffer = clCreateBuffer(context, CL_MEM_READ_WRITE, array_size_x * & 161 | array_size_y * c_float, C_NULL_PTR, err) 162 | 163 | if (err /= CL_SUCCESS) then 164 | print *, 'Error allocating device buffer: ', err 165 | call exit(1) 166 | end if 167 | 168 | print '(A,I10,A)', 'Successfuly allocated GPU device buffer, length: ',& 169 | array_size_x * array_size_y * c_float, ' bytes' 170 | 171 | ! Copy CPU data to device buffer. 172 | d_buffer_offset = 0 173 | err = clEnqueueWriteBuffer(cmd_queue, d_buffer, CL_TRUE, d_buffer_offset, & 174 | array_size_x * array_size_y * c_float, C_LOC(array1), 0, C_NULL_PTR, & 175 | C_NULL_PTR) 176 | 177 | if (err /= CL_SUCCESS) then 178 | print *, 'Error copying to device buffer: ', err 179 | call exit(1) 180 | end if 181 | 182 | ! Copy device buffer back to different CPU array. 183 | err = clEnqueueReadBuffer(cmd_queue, d_buffer, CL_TRUE, d_buffer_offset, & 184 | array_size_x * array_size_y * c_float, C_LOC(array2), 0, C_NULL_PTR, & 185 | C_NULL_PTR) 186 | 187 | if (err /= CL_SUCCESS) then 188 | print *, 'Error copying from device buffer: ', err 189 | call exit(1) 190 | end if 191 | 192 | ! Compare values. 193 | if (any(array1 /= array2)) then 194 | print *, 'Error, arrays are not equal!' 195 | call exit(1) 196 | end if 197 | 198 | print '(A)', 'Successfuly copied data to OpenCL device and back!' 199 | 200 | ! 201 | ! End of OpenCL logic. 202 | ! 203 | 204 | ! 205 | ! Release allocated handles. 206 | ! 207 | err = clReleaseMemObject(d_buffer) 208 | err = clReleaseCommandQueue(cmd_queue) 209 | err = clReleaseContext(context) 210 | end program create_device_context 211 | 212 | -------------------------------------------------------------------------------- /examples/create_device_context.f90: -------------------------------------------------------------------------------- 1 | ! ----------------------------------------------------------------------------- 2 | ! CLFORTRAN - OpenCL bindings module for Fortran. 3 | ! 4 | ! This is an example file that demonstrates using CLFORTRAN to create a basic 5 | ! OpenCL environment with a single GPU device (a matching context and a queue). 6 | ! 7 | ! Last Update: 18 March, 2014 8 | ! 9 | ! ----------------------------------------------------------------------------- 10 | ! 11 | ! Copyright (C) 2013-2014 Company for Advanced Supercomputing Solutions LTD 12 | ! Bosmat 2a St. 13 | ! Shoham 14 | ! Israel 60850 15 | ! http://www.cass-hpc.com 16 | ! 17 | ! Author: Mordechai Butrashvily 18 | ! 19 | ! ----------------------------------------------------------------------------- 20 | ! 21 | ! This program is free software: you can redistribute it and/or modify 22 | ! it under the terms of the GNU Lesser General Public License as published by 23 | ! the Free Software Foundation, either version 3 of the License, or 24 | ! (at your option) any later version. 25 | ! 26 | ! This program is distributed in the hope that it will be useful, 27 | ! but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | ! GNU Lesser General Public License for more details. 30 | ! 31 | ! You should have received a copy of the GNU Lesser General Public License 32 | ! along with this program. If not, see . 33 | ! 34 | ! ----------------------------------------------------------------------------- 35 | 36 | ! Main entry point. 37 | ! 38 | ! Queries available platforms, chooses the first and same for its devices. 39 | ! After selection is made, a context is created with command queue. 40 | program create_device_context 41 | use clfortran 42 | use ISO_C_BINDING 43 | implicit none 44 | 45 | ! Variable definitions for OpenCL API and in general. 46 | integer(c_int32_t) :: err 47 | integer(c_size_t) :: zero_size = 0 48 | integer(c_size_t) :: temp_size 49 | integer(c_int) :: num_platforms 50 | integer(c_int) :: num_devices 51 | integer(c_intptr_t), allocatable, target :: platform_ids(:) 52 | integer(c_intptr_t), allocatable, target :: device_ids(:) 53 | 54 | integer(c_intptr_t), target :: ctx_props(3) 55 | integer(c_intptr_t), target :: context 56 | integer(c_int64_t) :: cmd_queue_props 57 | integer(c_intptr_t), target :: cmd_queue 58 | 59 | print '(A)', 'OpenCL sample for creating context and queue for GPU device' 60 | 61 | ! Get the number of platforms, prior to allocating an array. 62 | err = clGetPlatformIDs(0, C_NULL_PTR, num_platforms) 63 | if (err /= CL_SUCCESS) then 64 | print *, 'Error quering platforms: ', err 65 | call exit(1) 66 | end if 67 | 68 | if (num_platforms == 0) then 69 | print *, 'No platforms found' 70 | call exit(0) 71 | end if 72 | 73 | ! Allocate an array to hold platform handles. 74 | allocate(platform_ids(num_platforms)) 75 | 76 | ! Get platforms IDs. 77 | err = clGetPlatformIDs(num_platforms, C_LOC(platform_ids), num_platforms) 78 | if (err /= CL_SUCCESS) then 79 | print *, 'Error getting platforms: ', err 80 | call exit(1) 81 | end if 82 | 83 | ! 84 | ! Check number of devices for first platform. 85 | ! 86 | err = clGetDeviceIDs(platform_ids(1), CL_DEVICE_TYPE_GPU, 0, C_NULL_PTR, & 87 | num_devices) 88 | if (err /= CL_SUCCESS) then 89 | print *, 'Error quering devices: ', err 90 | call exit(1) 91 | end if 92 | 93 | if (num_devices == 0) then 94 | print *, 'No GPU devices found' 95 | call exit(0) 96 | end if 97 | 98 | ! Allocate an array to hold device handles. 99 | allocate(device_ids(num_devices)) 100 | 101 | ! Get device IDs. 102 | err = clGetDeviceIDs(platform_ids(1), CL_DEVICE_TYPE_GPU, num_devices, & 103 | C_LOC(device_ids), num_devices) 104 | if (err /= CL_SUCCESS) then 105 | print *, 'Error gettings devices: ', err 106 | call exit(1) 107 | end if 108 | 109 | ! 110 | ! Create a context and a command queue. 111 | ! 112 | 113 | ! Context. 114 | num_devices = 1 115 | ctx_props(1) = CL_CONTEXT_PLATFORM 116 | ctx_props(2) = platform_ids(1) 117 | ctx_props(3) = 0 118 | 119 | context = clCreateContext(C_LOC(ctx_props), num_devices, & 120 | C_LOC(device_ids), C_NULL_FUNPTR, C_NULL_PTR, err) 121 | 122 | if (err /= CL_SUCCESS) then 123 | print *, 'Error creating context: ', err 124 | call exit(1) 125 | end if 126 | 127 | ! Command queue. 128 | cmd_queue_props = 0 129 | cmd_queue = clCreateCommandQueue(context, device_ids(1), cmd_queue_props, err) 130 | 131 | if (err /= CL_SUCCESS) then 132 | print *, 'Error creating command queue: ', err 133 | call exit(1) 134 | end if 135 | 136 | print '(A)', 'Successfuly create OpenCL context and queue for GPU device' 137 | 138 | ! 139 | ! Start OpenCL logic here. 140 | ! 141 | 142 | ! 143 | ! End of OpenCL logic. 144 | ! 145 | 146 | ! 147 | ! Release allocated handles. 148 | ! 149 | err = clReleaseCommandQueue(cmd_queue) 150 | err = clReleaseContext(context) 151 | end program create_device_context 152 | -------------------------------------------------------------------------------- /examples/query_platforms_devices.f90: -------------------------------------------------------------------------------- 1 | ! ----------------------------------------------------------------------------- 2 | ! CLFORTRAN - OpenCL bindings module for Fortran. 3 | ! 4 | ! This is an example file that demonstrates using CLFORTRAN to query available 5 | ! platforms and devices in the system, using the OpenCL API directly. 6 | ! 7 | ! Last Update: 18 March, 2014 8 | ! 9 | ! ----------------------------------------------------------------------------- 10 | ! 11 | ! Copyright (C) 2013-2014 Company for Advanced Supercomputing Solutions LTD 12 | ! Bosmat 2a St. 13 | ! Shoham 14 | ! Israel 60850 15 | ! http://www.cass-hpc.com 16 | ! 17 | ! Author: Mordechai Butrashvily 18 | ! 19 | ! ----------------------------------------------------------------------------- 20 | ! 21 | ! This program is free software: you can redistribute it and/or modify 22 | ! it under the terms of the GNU Lesser General Public License as published by 23 | ! the Free Software Foundation, either version 3 of the License, or 24 | ! (at your option) any later version. 25 | ! 26 | ! This program is distributed in the hope that it will be useful, 27 | ! but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | ! GNU Lesser General Public License for more details. 30 | ! 31 | ! You should have received a copy of the GNU Lesser General Public License 32 | ! along with this program. If not, see . 33 | ! 34 | ! ----------------------------------------------------------------------------- 35 | 36 | ! Main entry point. 37 | ! 38 | ! Checks the number of available platforms, and calls a specific query 39 | ! subroutine to print additional details on each platform (and attached 40 | ! devices). 41 | program query_platforms_devices 42 | use clfortran 43 | use ISO_C_BINDING 44 | implicit none 45 | 46 | ! Variable definitions for OpenCL API and in general. 47 | integer(c_int32_t) :: err 48 | integer(c_size_t) :: zero_size = 0 49 | integer(c_size_t) :: temp_size 50 | integer(c_int) :: num_platforms 51 | integer(c_int) :: i 52 | integer(c_intptr_t), allocatable, target :: platform_ids(:) 53 | 54 | ! Get the number of platforms, prior to allocating an array. 55 | err = clGetPlatformIDs(0, C_NULL_PTR, num_platforms) 56 | if (err /= CL_SUCCESS) then 57 | print *, 'Error quering platforms: ', err 58 | call exit(1) 59 | end if 60 | 61 | print '(A, I2)', 'Num Platforms: ', num_platforms 62 | 63 | ! Allocate an array to hold platform handles. 64 | allocate(platform_ids(num_platforms)) 65 | 66 | ! Get platforms IDs. 67 | err = clGetPlatformIDs(num_platforms, C_LOC(platform_ids), num_platforms) 68 | if (err /= CL_SUCCESS) then 69 | print *, 'Error quering platforms: ', err 70 | call exit(1) 71 | end if 72 | 73 | ! 74 | ! Header for platform details and devices. 75 | ! 76 | print * 77 | print '(A)', 'Platform Details:' 78 | print '(A)', '-----------------' 79 | 80 | ! Loop over platforms and print information. 81 | do i = 1, num_platforms 82 | ! Iterate over platforms and get number of devices. 83 | print '(A, I2)', 'Platform: ', i 84 | print * 85 | 86 | ! Query platform information. 87 | call query_platform_info(platform_ids(i)) 88 | 89 | ! Print separator between platforms, half size. 90 | print '(A)', '--------' 91 | end do 92 | end program query_platforms_devices 93 | 94 | ! Queries OpenCL platform for additional details (see OpenCL manual for more 95 | ! options) and included devices. 96 | ! 97 | ! Parameters: 98 | ! @platform_id - OpenCL handle of platform to query. 99 | ! 100 | subroutine query_platform_info(platform_id) 101 | use clfortran 102 | use ISO_C_BINDING 103 | implicit none 104 | 105 | ! Input variable. 106 | integer(c_intptr_t), intent(in) :: platform_id 107 | 108 | ! Helper variables to work with OpenCL API. 109 | integer(c_int32_t) :: err 110 | integer(c_size_t) :: zero_size = 0 111 | integer(c_size_t) :: temp_size 112 | ! For quering devices. 113 | integer(c_int64_t) :: device_type 114 | integer(c_int32_t) :: num_devices 115 | integer(c_int) :: i 116 | integer(c_intptr_t), allocatable, target :: device_ids(:) 117 | 118 | ! String arrays for holding platform details. 119 | character, allocatable, target :: platform_profile(:) 120 | character, allocatable, target :: platform_version(:) 121 | character, allocatable, target :: platform_name(:) 122 | character, allocatable, target :: platform_vendor(:) 123 | character, allocatable, target :: platform_extensions(:) 124 | 125 | ! String array for holding device name. 126 | character, allocatable, target :: device_name(:) 127 | ! Maximum compute units for device. 128 | integer(c_int32_t), target :: device_cu 129 | 130 | ! Profile. 131 | err = clGetPlatformInfo(platform_id, CL_PLATFORM_PROFILE, zero_size, C_NULL_PTR, temp_size) 132 | allocate(platform_profile(temp_size)) 133 | err = clGetPlatformInfo(platform_id, CL_PLATFORM_PROFILE, temp_size, C_LOC(platform_profile), temp_size) 134 | print *, 'Profile: ', platform_profile 135 | deallocate(platform_profile) 136 | 137 | ! Version. 138 | err = clGetPlatformInfo(platform_id, CL_PLATFORM_VERSION, zero_size, C_NULL_PTR, temp_size) 139 | allocate(platform_version(temp_size)) 140 | err = clGetPlatformInfo(platform_id, CL_PLATFORM_VERSION, temp_size, C_LOC(platform_version), temp_size) 141 | print *, 'Version: ', platform_version 142 | deallocate(platform_version) 143 | 144 | ! Name. 145 | err = clGetPlatformInfo(platform_id, CL_PLATFORM_NAME, zero_size, C_NULL_PTR, temp_size) 146 | allocate(platform_name(temp_size)) 147 | err = clGetPlatformInfo(platform_id, CL_PLATFORM_NAME, temp_size, C_LOC(platform_name), temp_size) 148 | print *, 'Name: ', platform_name 149 | deallocate(platform_name) 150 | 151 | ! Vendor. 152 | err = clGetPlatformInfo(platform_id, CL_PLATFORM_VENDOR, zero_size, C_NULL_PTR, temp_size) 153 | allocate(platform_vendor(temp_size)) 154 | err = clGetPlatformInfo(platform_id, CL_PLATFORM_VENDOR, temp_size, C_LOC(platform_vendor), temp_size) 155 | print *, 'Vendor: ', platform_vendor 156 | deallocate(platform_vendor) 157 | 158 | ! Extensions. 159 | err = clGetPlatformInfo(platform_id, CL_PLATFORM_EXTENSIONS, zero_size, C_NULL_PTR, temp_size) 160 | allocate(platform_extensions(temp_size)) 161 | err = clGetPlatformInfo(platform_id, CL_PLATFORM_EXTENSIONS, temp_size, C_LOC(platform_extensions), temp_size) 162 | print *, 'Extensions: ', platform_extensions 163 | deallocate(platform_extensions) 164 | 165 | ! 166 | ! Print device information for this platform. 167 | ! 168 | ! Get device count. 169 | !device_type = CL_DEVICE_TYPE_ALL 170 | err = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL, 0, C_NULL_PTR, num_devices) 171 | 172 | if (err /= CL_SUCCESS .or. num_devices < 1) then 173 | print *, 'No devices found: ', err 174 | return 175 | end if 176 | 177 | print * 178 | print '(A, I2)', 'Num Devices: ', num_devices 179 | 180 | ! Allocate an array to hold device handles. 181 | allocate(device_ids(num_devices)) 182 | 183 | ! Get device IDs. 184 | err = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_ALL, num_devices, C_LOC(device_ids), num_devices) 185 | if (err /= CL_SUCCESS) then 186 | print *, 'Error quering devices: ', err 187 | return 188 | end if 189 | 190 | ! Loop over devices and print information. 191 | do i = 1, num_devices 192 | ! Maximum compute units. 193 | temp_size = 4 194 | err = clGetDeviceInfo(device_ids(i), CL_DEVICE_MAX_COMPUTE_UNITS, temp_size, C_LOC(device_cu), temp_size) 195 | 196 | ! Name. 197 | err = clGetDeviceInfo(device_ids(i), CL_DEVICE_NAME, zero_size, C_NULL_PTR, temp_size) 198 | allocate(device_name(temp_size)) 199 | err = clGetDeviceInfo(device_ids(i), CL_DEVICE_NAME, temp_size, C_LOC(device_name), temp_size) 200 | 201 | ! Print brief device details. 202 | write (*, '(A,I2,A,I3,A)', advance='no') ' Device (#', i, ', Compute Units: ', device_cu, ') - ' 203 | print *, device_name 204 | 205 | deallocate(device_name) 206 | end do 207 | end subroutine query_platform_info 208 | -------------------------------------------------------------------------------- /examples/sum.cl: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2011 X. Andrade 2 | ** 3 | ** FortranCL is free software: you can redistribute it and/or modify 4 | ** it under the terms of the GNU Lesser General Public License as published by 5 | ** the Free Software Foundation, either version 3 of the License, or 6 | ** (at your option) any later version. 7 | ** 8 | ** FortranCL is distributed in the hope that it will be useful, 9 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | ** GNU Lesser General Public License for more details. 12 | ** 13 | ** You should have received a copy of the GNU Lesser General Public License 14 | ** along with this program. If not, see . 15 | ** 16 | ** $Id$ 17 | **/ 18 | 19 | __kernel void sum(const int size, const __global float * vec1, __global float * vec2){ 20 | int ii = get_global_id(0); 21 | 22 | if(ii < size) vec2[ii] += vec1[ii]; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /examples/sum.f90: -------------------------------------------------------------------------------- 1 | c gfortran -fcheck=all -ffixed-form -fbacktrace -L/usr/lib64/nvidia -lOpenCL -o sum sum.f 2 | c srun --gres=gpu ./sum 3 | c 4 | c uses module clfortran.mod 5 | c 6 | program sum 7 | use clfortran 8 | use ISO_C_BINDING 9 | implicit none 10 | 11 | integer irec,i,iallocerr,iplatform,idevice 12 | integer, parameter :: iunit=10 13 | 14 | integer(c_int32_t) :: ierr,num_devices,num_platforms 15 | integer(c_size_t) :: iret,size_in_bytes,zero_size= 0 16 | character, dimension(1) :: char 17 | character(len=1024) :: options,kernel_name 18 | 19 | c C_LOC determines the C address of an object 20 | c The variable type must be either a pointer or a target 21 | integer, target :: isize 22 | integer(c_size_t),target :: globalsize,localsize 23 | integer(c_int32_t), target :: device_cu,build_log 24 | integer(c_intptr_t), allocatable, target :: 25 | & platform_ids(:),device_ids(:) 26 | integer(c_intptr_t), target :: 27 | & ctx_props(3),context,cmd_queue,prog,kernel,cl_vec1,cl_vec2 28 | character(len=1,kind=c_char), allocatable, target :: 29 | & source(:),device_name(:) 30 | character(len=1,kind=c_char), target :: 31 | & source2(1:1024),retinfo(1:1024), 32 | & c_options(1:1024),c_kernel_name(1:1024) 33 | real, allocatable, target :: vec1(:), vec2(:) 34 | type(c_ptr), target :: psource 35 | 36 | 37 | 38 | 39 | 40 | print '(///)' 41 | 42 | 43 | ierr=clGetPlatformIDs(0,C_NULL_PTR,num_platforms) 44 | if ((ierr.ne.CL_SUCCESS).or.(num_platforms.lt.1)) 45 | & print *,'clGetPlatformIDs',ierr 46 | print '(a,i2)','Num Platforms: ',num_platforms 47 | allocate(platform_ids(num_platforms),stat=iallocerr) 48 | if (iallocerr.ne.0) stop 'memory allocation error' 49 | c whenever "&" appears in C subroutine (address-off) call, 50 | c then C_LOC has to be used in Fortran 51 | ierr=clGetPlatformIDs(num_platforms,C_LOC(platform_ids), 52 | & num_platforms) 53 | if (ierr.ne.CL_SUCCESS) stop 'clGetPlatformIDs' 54 | 55 | 56 | c Get device IDs only for platform 1 57 | iplatform=1 58 | 59 | 60 | ierr=clGetDeviceIDs(platform_ids(iplatform),CL_DEVICE_TYPE_ALL, 61 | & 0,C_NULL_PTR,num_devices) 62 | if ((ierr.ne.CL_SUCCESS).or.(num_devices.lt.1)) 63 | & stop 'clGetDeviceIDs' 64 | print '(a,i2)','Num Devices: ',num_devices 65 | allocate(device_ids(num_devices),stat=iallocerr) 66 | if (iallocerr.ne.0) stop 'memory allocation error' 67 | c whenever "&" appears in C subroutine (address-off) call, 68 | c then C_LOC has to be used in Fortran 69 | ierr=clGetDeviceIDs(platform_ids(iplatform),CL_DEVICE_TYPE_ALL, 70 | & num_devices,C_LOC(device_ids),num_devices) 71 | if (ierr.ne.CL_SUCCESS) stop 'clGetDeviceIDs' 72 | 73 | 74 | c Get device info only for device 1 75 | idevice=1 76 | 77 | 78 | ierr=clGetDeviceInfo(device_ids(idevice), 79 | & CL_DEVICE_MAX_COMPUTE_UNITS,sizeof(device_cu), 80 | & C_LOC(device_cu),iret) 81 | if (ierr.ne.CL_SUCCESS) stop 'clGetDeviceInfo' 82 | ierr=clGetDeviceInfo(device_ids(idevice), 83 | & CL_DEVICE_NAME,zero_size,C_NULL_PTR,iret) 84 | if (ierr.ne.CL_SUCCESS) stop 'clGetDeviceInfo' 85 | allocate(device_name(iret),stat=iallocerr) 86 | if (iallocerr.ne.0) stop 'allocate' 87 | ierr=clGetDeviceInfo(device_ids(idevice), 88 | & CL_DEVICE_NAME,sizeof(device_name),C_LOC(device_name),iret) 89 | if (ierr.ne.CL_SUCCESS) stop 'clGetDeviceInfo' 90 | write (*,'(a,i2,a,i3,a)',advance='no') 91 | & ' Device (#',idevice,', Compute Units: ',device_cu,') - ' 92 | print *,device_name(1:iret) 93 | deallocate(device_name) 94 | 95 | 96 | print '(a,i2,a)', 'Creating context for: ', num_devices,' devices' 97 | print '(a,i2)', 'for platform: ',iplatform 98 | ctx_props(1)=CL_CONTEXT_PLATFORM 99 | ctx_props(2)=platform_ids(iplatform) 100 | ctx_props(3)=0 101 | context=clCreateContext(C_LOC(ctx_props),num_devices, 102 | & C_LOC(device_ids),C_NULL_FUNPTR,C_NULL_PTR,ierr) 103 | if (ierr.ne.CL_SUCCESS) stop 'clCreateContext' 104 | 105 | 106 | cmd_queue=clCreateCommandQueue(context,device_ids(idevice), 107 | & CL_QUEUE_PROFILING_ENABLE,ierr) 108 | if (ierr.ne.CL_SUCCESS) stop 'clCreateCommandQueue' 109 | 110 | 111 | c read kernel from disk 112 | open(iunit,file='sum.cl',access='direct', 113 | & status='old',action='read',iostat=ierr,recl=1) 114 | if (ierr.ne.0) stop 'Cannot open file sum.cl' 115 | irec=1 116 | 10 continue 117 | read(iunit,rec=irec,iostat=ierr) char 118 | if (ierr.ne.0) goto 11 119 | irec=irec+1 120 | goto 10 121 | 11 continue 122 | if (irec.eq.0) stop 'nothing read' 123 | allocate(source(irec+1),stat=iallocerr) 124 | if (iallocerr.ne.0) stop 'allocate' 125 | do i=1,irec 126 | read(iunit,rec=i,iostat=ierr) source(i:i) 127 | enddo 128 | close(iunit) 129 | c print '(a)','**** CL SOURCE CODE START ****' 130 | c print '(1024a)',source(1:irec) 131 | c print '(a)','**** CL SOURCE CODE END ****' 132 | print '(a,i4)','size of source code in bytes: ',irec 133 | c in C, strings end with c_null_char 134 | source(irec+1)=C_NULL_CHAR 135 | 136 | 137 | psource=C_LOC(source) ! pointer to source code 138 | prog=clCreateProgramWithSource(context,1, 139 | & C_LOC(psource),C_NULL_PTR,ierr) 140 | if (ierr.ne.CL_SUCCESS) stop 'clCreateProgramWithSource' 141 | 142 | 143 | print '(///)' 144 | 145 | 146 | c check if program has uploaded successfully to CL device 147 | ierr=clGetProgramInfo(prog,CL_PROGRAM_SOURCE, 148 | & sizeof(source2),C_LOC(source2),iret) 149 | if (ierr.ne.CL_SUCCESS) stop 'clGetProgramInfo' 150 | print '(a)','**** code retrieved from device start ****' 151 | print '(1024a)',source2(1:min(iret,1024)) 152 | print '(a)','**** code retrieved from device end ****' 153 | 154 | 155 | print '(///)' 156 | 157 | 158 | options='-cl-opt-disable' ! compiler options 159 | irec=len(trim(options)) 160 | do i=1,irec 161 | c_options(i)=options(i:i) 162 | enddo 163 | c_options(irec+1)=C_NULL_CHAR 164 | ierr=clBuildProgram(prog,0, 165 | & C_NULL_PTR,C_LOC(c_options),C_NULL_FUNPTR,C_NULL_PTR) 166 | if (ierr.ne.CL_SUCCESS) then 167 | print *,'clBuildProgram',ierr 168 | ierr=clGetProgramBuildInfo(prog,device_ids(idevice), 169 | & CL_PROGRAM_BUILD_LOG,sizeof(retinfo),C_LOC(retinfo),iret) 170 | if (ierr.ne.0) stop 'clGetProgramBuildInfo' 171 | print '(a)','build log start' 172 | print '(1024a)',retinfo(1:min(iret,1024)) 173 | print '(a)','build log end' 174 | stop 175 | endif 176 | 177 | 178 | kernel_name='sum' 179 | irec=len(trim(kernel_name)) 180 | do i=1,irec 181 | c_kernel_name(i)=kernel_name(i:i) 182 | enddo 183 | c_kernel_name(irec+1)=C_NULL_CHAR 184 | kernel=clCreateKernel(prog,C_LOC(c_kernel_name),ierr) 185 | if (ierr.ne.0) stop 'clCreateKernel' 186 | 187 | 188 | ierr=clReleaseProgram(prog) 189 | if (ierr.ne.0) stop 'clReleaseProgram' 190 | 191 | 192 | 193 | 194 | 195 | isize=1000 196 | size_in_bytes=int(isize,8)*4_8 197 | c Size of an element, typically: 198 | c 4_8 for integer or real 199 | c 8_8 for double precision or complex 200 | c 16_8 for double complex 201 | c second 8 indicates kind=8 (same is true for 8 in int() argument list) 202 | allocate(vec1(1:isize)) 203 | allocate(vec2(1:isize)) 204 | 205 | do i=1,isize 206 | vec1(i)=real(i) 207 | vec2(i)=real(isize-i) 208 | enddo 209 | 210 | 211 | c allocate device memory 212 | cl_vec1=clCreateBuffer(context,CL_MEM_READ_ONLY, 213 | & size_in_bytes,C_NULL_PTR,ierr) 214 | if (ierr.ne.0) stop 'clCreateBuffer' 215 | cl_vec2=clCreateBuffer(context,CL_MEM_READ_WRITE, 216 | & size_in_bytes,C_NULL_PTR,ierr) 217 | if (ierr.ne.0) stop 'clCreateBuffer' 218 | 219 | 220 | c copy data to device memory 221 | ierr=clEnqueueWriteBuffer(cmd_queue,cl_vec1, 222 | & CL_TRUE,0_8,size_in_bytes,C_LOC(vec1), 223 | & 0,C_NULL_PTR,C_NULL_PTR) 224 | c 0_8 is a zero of kind=8 225 | if (ierr.ne.0) stop 'clEnqueueWriteBuffer' 226 | ierr=clEnqueueWriteBuffer(cmd_queue,cl_vec2, 227 | & CL_TRUE,0_8,size_in_bytes,C_LOC(vec2), 228 | & 0,C_NULL_PTR,C_NULL_PTR) 229 | if (ierr.ne.0) stop 'clEnqueueWriteBuffer' 230 | 231 | 232 | c set the kernel arguments 233 | ierr=clSetKernelArg(kernel,0,sizeof(isize),C_LOC(isize)) 234 | if (ierr.ne.0) stop 'clSetKernelArg' 235 | ierr=clSetKernelArg(kernel,1,sizeof(cl_vec1),C_LOC(cl_vec1)) 236 | if (ierr.ne.0) stop 'clSetKernelArg' 237 | ierr=clSetKernelArg(kernel,2,sizeof(cl_vec2),C_LOC(cl_vec2)) 238 | if (ierr.ne.0) stop 'clSetKernelArg' 239 | 240 | 241 | c get the local size for the kernel 242 | ierr=clGetKernelWorkGroupInfo(kernel,device_ids(idevice), 243 | & CL_KERNEL_WORK_GROUP_SIZE,sizeof(localsize), 244 | & C_LOC(localsize),iret) 245 | if (ierr.ne.0) stop 'clGetKernelWorkGroupInfo' 246 | globalsize=int(isize,8) 247 | if (mod(globalsize,localsize).ne.0) globalsize= 248 | & globalsize+localsize-mod(globalsize,localsize) 249 | 250 | 251 | c execute the kernel 252 | ierr=clEnqueueNDRangeKernel(cmd_queue,kernel, 253 | & 1,C_NULL_PTR,C_LOC(globalsize),C_LOC(localsize), 254 | & 0,C_NULL_PTR,C_NULL_PTR) 255 | if (ierr.ne.0) stop 'clEnqueueNDRangeKernel' 256 | ierr=clFinish(cmd_queue) 257 | if (ierr.ne.0) stop 'clFinish' 258 | 259 | 260 | print '(a)','sent to device:' 261 | do i=1,10 262 | print '(2e12.5)',vec1(i),vec2(i) 263 | enddo 264 | 265 | 266 | c read the resulting vector from device memory 267 | ierr=clEnqueueReadBuffer(cmd_queue,cl_vec2, 268 | & CL_TRUE,0_8,size_in_bytes,C_LOC(vec2), 269 | & 0,C_NULL_PTR,C_NULL_PTR) 270 | if (ierr.ne.0) stop 'clEnqueueReadBuffer' 271 | 272 | 273 | print '(a)','retrieved from device:' 274 | do i=1,10 275 | print '(12x,e12.5)',vec2(i) 276 | enddo 277 | 278 | 279 | ierr=clReleaseKernel(kernel) 280 | if (ierr.ne.0) stop 'clReleaseKernel' 281 | ierr=clReleaseCommandQueue(cmd_queue) 282 | if (ierr.ne.0) stop 'clReleaseCommandQueue' 283 | ierr=clReleaseContext(context) 284 | if (ierr.ne.0) stop 'clReleaseContext' 285 | 286 | end 287 | 288 | 289 | 290 | 291 | 292 | 293 | c Argument lists need to be handled with care. Neither the C nor the Fortran compiler checks for mismatched argument types, or even a mismatch in the number of arguments. Some bizarre run-time errors therefore arise. Keep in mind that Fortran passes arguments by reference whereas C passes arguments by value. When you put a variable name into a function call from Fortran, the corresponding C function receives a pointer to that variable. Similarly, when calling a Fortran subroutine from C, you must explicitly pass addresses rather than values in the argument list. 294 | 295 | c When passing arrays, remember that C arrays start with subscript zero. Fortran stores multidimensional arrays in column-major order (first index varies fastest) whereas C stores them in row-major order (last index varies fastest). 296 | 297 | c Passing character strings is a special problem. C knows it has come to the end of string when it hits a null character, but Fortran uses the declared length of a string. The C-Fortran interface provides an extra argument for each character string in a C argument list to receive the declared length of a string when called from Fortran. Consider the following Fortran fragment: 298 | 299 | 300 | 301 | --------------------------------------------------------------------------------