10 #include <OpenImageIO/argparse.h>
11 #include <OpenImageIO/filesystem.h>
53 const char *headers[] = {
"stdlib.h",
"float.h",
"math.h",
"stdio.h",
"stddef.h"};
54 const char *header_content[] = {
"\n",
"\n",
"\n",
"\n",
"\n"};
56 printf(
"Building %s\n", settings.
input_file.c_str());
59 if (!OIIO::Filesystem::read_text_file(settings.
input_file, code)) {
60 fprintf(stderr,
"Error: unable to read %s\n", settings.
input_file.c_str());
65 for (
size_t i = 0; i < settings.
includes.size(); i++) {
69 for (
size_t i = 0; i < settings.
defines.size(); i++) {
74 options.push_back(
"--device-as-default-execution-space");
75 options.push_back(
"-DCYCLES_CUBIN_CC");
76 options.push_back(
"--std=c++11");
78 options.push_back(
"--use_fast_math");
81 nvrtcResult
result = nvrtcCreateProgram(&prog,
84 sizeof(headers) /
sizeof(
void *),
88 if (
result != NVRTC_SUCCESS) {
89 fprintf(stderr,
"Error: nvrtcCreateProgram failed (%d)\n\n", (
int)
result);
95 for (
size_t i = 0; i <
options.size(); i++) {
101 if (
result != NVRTC_SUCCESS) {
102 fprintf(stderr,
"Error: nvrtcCompileProgram failed (%d)\n\n", (
int)
result);
105 nvrtcGetProgramLogSize(prog, &log_size);
108 nvrtcGetProgramLog(prog, &
log[0]);
109 fprintf(stderr,
"%s\n", &
log[0]);
116 result = nvrtcGetPTXSize(prog, &ptx_size);
117 if (
result != NVRTC_SUCCESS) {
118 fprintf(stderr,
"Error: nvrtcGetPTXSize failed (%d)\n\n", (
int)
result);
123 result = nvrtcGetPTX(prog, &ptx_code[0]);
124 if (
result != NVRTC_SUCCESS) {
125 fprintf(stderr,
"Error: nvrtcGetPTX failed (%d)\n\n", (
int)
result);
133 settings.
ptx_file = OIIO::Filesystem::temp_directory_path() +
"/" +
134 OIIO::Filesystem::unique_path();
136 FILE *f = fopen(settings.
ptx_file.c_str(),
"wb");
137 fwrite(&ptx_code[0], 1, ptx_size, f);
145 string cudapath =
"";
149 string ptx =
"\"" + cudapath +
"ptxas\" " + settings.
ptx_file +
" -o " + settings.
output_file +
155 printf(
"%s\n", ptx.c_str());
158 int pxresult = system(ptx.c_str());
160 fprintf(stderr,
"Error: ptxas failed (%d)\n\n", pxresult);
165 fprintf(stderr,
"Error: removing %s\n\n", settings.
ptx_file.c_str());
181 int cuewresult = cuewInit(CUEW_INIT_NVRTC);
182 if (cuewresult != CUEW_SUCCESS) {
183 fprintf(stderr,
"Error: cuew init fialed (0x%d)\n\n", cuewresult);
187 if (cuewNvrtcVersion() < 80) {
188 fprintf(stderr,
"Error: only cuda 8 and higher is supported, %d\n\n", cuewCompilerVersion());
192 if (!nvrtcCreateProgram) {
193 fprintf(stderr,
"Error: nvrtcCreateProgram not resolved\n");
197 if (!nvrtcCompileProgram) {
198 fprintf(stderr,
"Error: nvrtcCompileProgram not resolved\n");
202 if (!nvrtcGetProgramLogSize) {
203 fprintf(stderr,
"Error: nvrtcGetProgramLogSize not resolved\n");
207 if (!nvrtcGetProgramLog) {
208 fprintf(stderr,
"Error: nvrtcGetProgramLog not resolved\n");
212 if (!nvrtcGetPTXSize) {
213 fprintf(stderr,
"Error: nvrtcGetPTXSize not resolved\n");
218 fprintf(stderr,
"Error: nvrtcGetPTX not resolved\n");
228 ap.options(
"Usage: cycles_cubin_cc [options]",
231 "target shader model",
234 "Cuda architecture bits",
237 "Input source filename",
240 "Output cubin filename",
243 "Add additional includepath",
246 "Add additional defines",
252 "Use verbose logging",
256 "-cuda-toolkit-dir %s",
258 "path to the cuda toolkit binary directory",
261 if (ap.parse(argc, argv) < 0) {
262 fprintf(stderr,
"%s\n", ap.geterror().c_str());
268 fprintf(stderr,
"Error: Output file not set(-o), required\n\n");
273 fprintf(stderr,
"Error: Input file not set(-i, required\n\n");
278 fprintf(stderr,
"Error: target shader model not set (-target), required\n\n");
285 int main(
int argc,
const char **argv)
290 fprintf(stderr,
"Error: invalid parameters, exiting\n");
294 if (!
init(settings)) {
295 fprintf(stderr,
"Error: initialization error, exiting\n");
300 fprintf(stderr,
"Error: compilation error, exiting\n");
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a vector
vector< string > includes
int main(int argc, const char **argv)
static bool init(CompilationSettings &settings)
static bool link_ptxas(CompilationSettings &settings)
static bool parse_parameters(int argc, const char **argv, CompilationSettings &settings)
static bool compile_cuda(CompilationSettings &settings)
CCL_NAMESPACE_BEGIN struct Options options
SyclQueue void void size_t num_bytes void
ccl_device_inline float3 log(float3 v)
bool remove(void *owner, const AttributeIDRef &attribute_id)
std::string to_string(const T &n)