mirror of
https://github.com/AdaCore/cuda.git
synced 2026-02-12 13:05:54 -08:00
updated elaboration example following latest fixes
This commit is contained in:
@@ -14,17 +14,17 @@ project CUDA_API_Host is
|
||||
for Switches ("ada") use (
|
||||
"-L/usr/local/cuda/targets/" & CUDA_Host & "/lib",
|
||||
"-L/usr/local/cuda/targets/" & CUDA_Host & "/lib/stubs",
|
||||
"-lcudadevrt",
|
||||
"-lcudart_static",
|
||||
"-lrt",
|
||||
"-lpthread",
|
||||
"-lcudadevrt",
|
||||
"-lcudart_static",
|
||||
"-lrt",
|
||||
"-lpthread",
|
||||
"-ldl",
|
||||
"-Wl,--unresolved-symbols=ignore-all"
|
||||
);
|
||||
end Linker;
|
||||
|
||||
package Binder is
|
||||
for Default_Switches ("ada") use ("-d_c");
|
||||
for Default_Switches ("ada") use ("-d_c=device");
|
||||
end Binder;
|
||||
|
||||
|
||||
end CUDA_API_Host;
|
||||
|
||||
@@ -1,17 +1,28 @@
|
||||
with "cuda_api_device.gpr";
|
||||
|
||||
aggregate library project Device is
|
||||
for Project_Files use ("../../../api/cuda_api_device.gpr", "device_code.gpr");
|
||||
for Library_Name use "device";
|
||||
for Library_Dir use "lib";
|
||||
for Library_Interface use ("kernel");
|
||||
|
||||
for Target use "cuda";
|
||||
library project Device is
|
||||
|
||||
for Archive_Builder use CUDA_API_Device'Archive_Builder;
|
||||
for Library_Interface use ("kernel");
|
||||
|
||||
package Binder is
|
||||
for Languages use ("Ada");
|
||||
for Source_Dirs use ("src/common");
|
||||
for Object_Dir use "obj/device";
|
||||
|
||||
for Target use "cuda";
|
||||
for Library_Name use "kernel";
|
||||
for Library_Dir use "lib/device_code";
|
||||
for Library_Standalone use "encapsulated";
|
||||
for Library_Kind use "dynamic";
|
||||
|
||||
package Compiler is
|
||||
for Switches ("ada") use CUDA_API_Device.Compiler'Switches ("ada");
|
||||
end Compiler;
|
||||
|
||||
package Binder is
|
||||
for Driver ("ada") use "llvm-gnatbind";
|
||||
for Default_Switches ("ada") use CUDA_API_Device.Binder'Default_Switches ("ada") & ("-t");
|
||||
end Binder;
|
||||
end Binder;
|
||||
|
||||
end Device;
|
||||
for Archive_Builder use CUDA_API_Device'Archive_Builder;
|
||||
|
||||
end Device;
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
with "cuda_api_device.gpr";
|
||||
|
||||
library project Device_Code is
|
||||
|
||||
for Library_Interface use ("kernel");
|
||||
|
||||
for Languages use ("Ada");
|
||||
for Source_Dirs use ("src/common");
|
||||
for Object_Dir use "obj/device";
|
||||
|
||||
for Target use "cuda";
|
||||
for Library_Name use "kernel";
|
||||
for Library_Dir use "lib/device_code";
|
||||
|
||||
package Compiler is
|
||||
for Switches ("ada") use CUDA_API_Device.Compiler'Switches ("ada");
|
||||
end Compiler;
|
||||
|
||||
package Binder is
|
||||
for Driver ("ada") use "llvm-gnatbind";
|
||||
for Default_Switches ("ada") use CUDA_API_Device.Binder'Default_Switches ("ada") & ("-t");
|
||||
end Binder;
|
||||
|
||||
for Archive_Builder use CUDA_API_Device'Archive_Builder;
|
||||
|
||||
end Device_Code;
|
||||
@@ -2,8 +2,6 @@ with CUDA.Runtime_Api; use CUDA.Runtime_Api; -- Block_Dim, Block_IDx, Thread_IDx
|
||||
with Interfaces.C; use Interfaces.C; -- Operators for Block_Dim, Block_IDx, Thread_IDx
|
||||
|
||||
package body Kernel is
|
||||
|
||||
X : Float := 0.0;
|
||||
|
||||
procedure Vector_Add
|
||||
(A_Addr : System.Address;
|
||||
@@ -17,14 +15,14 @@ package body Kernel is
|
||||
I : Integer := Integer (Block_Dim.X * Block_IDx.X + Thread_IDx.X);
|
||||
begin
|
||||
if I < Num_Elements then
|
||||
C (C'First + I) := A (A'First + I) + B (B'First + I) + X;
|
||||
C (C'First + I) := A (A'First + I) + B (B'First + I) + Elaborated_Value;
|
||||
end if;
|
||||
end Vector_Add;
|
||||
|
||||
begin
|
||||
|
||||
for I in 1 .. 10_000 loop
|
||||
X := X + 1.0;
|
||||
Elaborated_Value := Elaborated_Value + 1.0;
|
||||
end loop;
|
||||
|
||||
end Kernel;
|
||||
|
||||
@@ -2,6 +2,8 @@ with System;
|
||||
|
||||
package Kernel is
|
||||
|
||||
Elaborated_Value : Float := 0.0;
|
||||
|
||||
type Float_Array is array (Integer range <>) of Float;
|
||||
|
||||
type Access_Host_Float_Array is access all Float_Array;
|
||||
|
||||
@@ -83,8 +83,14 @@ begin
|
||||
Count => Array_Size,
|
||||
Kind => Memcpy_Device_To_Host);
|
||||
|
||||
if Elaborated_Value /= 10_000.0 then
|
||||
Put_Line ("Error in computation of Elaborated_Value!");
|
||||
|
||||
return;
|
||||
end if;
|
||||
|
||||
for I in 1..Num_Elements loop
|
||||
if abs (H_A (I) + H_B (I) - H_C (I)) > 1.0E-5 then
|
||||
if abs (H_A (I) + H_B (I) + Elaborated_Value - H_C (I)) > 1.0E-5 then
|
||||
Put_Line ("Result verification failed at element "& I'Img & "!");
|
||||
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user