1 //===-- Main entry into the loader interface ------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file opens a device image passed on the command line and passes it to
10 // one of the loader implementations for launch.
12 //===----------------------------------------------------------------------===//
21 int main(int argc
, char **argv
, char **envp
) {
23 printf("USAGE: ./loader [--threads <n>, --blocks <n>] <device_image> "
31 LaunchParameters params
= {1, 1, 1, 1, 1, 1};
32 while (!file
&& ++offset
< argc
) {
33 if (argv
[offset
] == std::string("--threads") ||
34 argv
[offset
] == std::string("--threads-x")) {
35 params
.num_threads_x
=
36 offset
+ 1 < argc
? strtoul(argv
[offset
+ 1], &ptr
, 10) : 1;
39 } else if (argv
[offset
] == std::string("--threads-y")) {
40 params
.num_threads_y
=
41 offset
+ 1 < argc
? strtoul(argv
[offset
+ 1], &ptr
, 10) : 1;
44 } else if (argv
[offset
] == std::string("--threads-z")) {
45 params
.num_threads_z
=
46 offset
+ 1 < argc
? strtoul(argv
[offset
+ 1], &ptr
, 10) : 1;
49 } else if (argv
[offset
] == std::string("--blocks") ||
50 argv
[offset
] == std::string("--blocks-x")) {
52 offset
+ 1 < argc
? strtoul(argv
[offset
+ 1], &ptr
, 10) : 1;
55 } else if (argv
[offset
] == std::string("--blocks-y")) {
57 offset
+ 1 < argc
? strtoul(argv
[offset
+ 1], &ptr
, 10) : 1;
60 } else if (argv
[offset
] == std::string("--blocks-z")) {
62 offset
+ 1 < argc
? strtoul(argv
[offset
+ 1], &ptr
, 10) : 1;
66 file
= fopen(argv
[offset
], "r");
68 fprintf(stderr
, "Failed to open image file '%s'\n", argv
[offset
]);
76 fprintf(stderr
, "No image file provided\n");
80 // TODO: We should perform some validation on the file.
81 fseek(file
, 0, SEEK_END
);
82 const auto size
= ftell(file
);
83 fseek(file
, 0, SEEK_SET
);
85 void *image
= malloc(size
* sizeof(char));
86 fread(image
, sizeof(char), size
, file
);
89 // Drop the loader from the program arguments.
90 int ret
= load(argc
- offset
, &argv
[offset
], envp
, image
, size
, params
);