3 * Copyright 2010 NVIDIA Corporation. All rights reserved.
5 * NOTICE TO USER: The source code, and related code and software
6 * ("Code"), is copyrighted under U.S. and international laws.
8 * NVIDIA Corporation owns the copyright and any patents issued or
9 * pending for the Code.
11 * NVIDIA CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY
12 * OF THIS CODE FOR ANY PURPOSE. IT IS PROVIDED "AS-IS" WITHOUT EXPRESS
13 * OR IMPLIED WARRANTY OF ANY KIND. NVIDIA CORPORATION DISCLAIMS ALL
14 * WARRANTIES WITH REGARD TO THE CODE, INCLUDING NON-INFRINGEMENT, AND
15 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
18 * WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATED TO THE USE OR
19 * PERFORMANCE OF THE CODE, INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT,
20 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
21 * NEGLIGENCE OR OTHER TORTIOUS ACTION, AND WHETHER OR NOT THE
22 * POSSIBILITY OF SUCH DAMAGES WERE KNOWN OR MADE KNOWN TO NVIDIA
27 #ifndef fatbinaryctl_INCLUDED
28 #define fatbinaryctl_INCLUDED
30 #ifndef __CUDA_INTERNAL_COMPILATION__
31 #include <stddef.h> /* for size_t */
33 #include "fatbinary.h"
36 * These are routines for controlling the fat binary.
37 * A void* object is used, with ioctl-style calls to set and get info from it.
42 FBCTL_ERROR_NULL, /* null pointer */
43 FBCTL_ERROR_UNRECOGNIZED, /* unrecognized kind */
44 FBCTL_ERROR_NO_CANDIDATE, /* no candidate found */
45 FBCTL_ERROR_COMPILE_FAILED, /* no candidate found */
46 FBCTL_ERROR_INTERNAL /* unexpected internal error */
47 } fatBinaryCtlError_t;
48 extern char* fatBinaryCtl_Errmsg (fatBinaryCtlError_t e);
50 extern fatBinaryCtlError_t fatBinaryCtl_Create (void* *data);
52 extern void fatBinaryCtl_Delete (void* data);
54 /* use this control-call to set and get values */
55 extern fatBinaryCtlError_t fatBinaryCtl (void* data, int request, ...);
57 /* defined requests */
58 #define FBCTL_SET_BINARY 1 /* void* (e.g. fatbin, elf or ptx object) */
59 #define FBCTL_SET_TARGETSM 2 /* int (use values from nvelf.h) */
60 #define FBCTL_SET_FLAGS 3 /* longlong */
61 #define FBCTL_SET_CMDOPTIONS 4 /* char* */
62 #define FBCTL_SET_POLICY 5 /* fatBinary_CompilationPolicy */
63 /* get calls return value in arg, thus are all by reference */
64 #define FBCTL_GET_CANDIDATE 10 /* void** binary,
65 * fatBinaryCodeKind* kind,
67 #define FBCTL_GET_IDENTIFIER 11 /* char* * */
68 #define FBCTL_HAS_DEBUG 12 /* Bool * */
71 fatBinary_PreferBestCode, /* default */
72 fatBinary_AvoidPTX, /* use sass if possible for compile-time savings */
73 fatBinary_ForcePTX, /* use ptx (mainly for testing) */
74 fatBinary_JITIfNotMatch /* use ptx if arch doesn't match */
75 } fatBinary_CompilationPolicy;
78 * Using the input values, pick the best candidate;
79 * use subsequent Ctl requests to get info about that candidate.
81 extern fatBinaryCtlError_t fatBinaryCtl_PickCandidate (void* data);
84 * Using the previously chosen candidate, compile the code to elf,
85 * returning elf image and size.
86 * Note that because elf is allocated inside fatBinaryCtl,
87 * it will be freed when _Delete routine is called.
89 extern fatBinaryCtlError_t fatBinaryCtl_Compile (void* data,
90 void* *elf, size_t *esize);
93 * These defines are for the fatbin.c runtime wrapper
95 #define FATBINC_MAGIC 0x466243B1
96 #define FATBINC_VERSION 1
97 #define FATBINC_LINK_VERSION 2
102 const unsigned long long* data;
103 void *filename_or_fatbins; /* version 1: offline filename,
104 * version 2: array of prelinked fatbins */
105 } __fatBinC_Wrapper_t;
108 * The section that contains the fatbin control structure
111 /* mach-o sections limited to 15 chars, and want __ prefix else strip complains, * so use a different name */
112 #define FATBIN_CONTROL_SECTION_NAME "__fatbin"
113 #define FATBIN_DATA_SECTION_NAME "__nv_fatbin"
114 /* only need segment name for mach-o */
115 #define FATBIN_SEGMENT_NAME "__NV_CUDA"
117 #define FATBIN_CONTROL_SECTION_NAME ".nvFatBinSegment"
119 * The section that contains the fatbin data itself
120 * (put in separate section so easy to find)
122 #define FATBIN_DATA_SECTION_NAME ".nv_fatbin"
124 /* section for pre-linked relocatable fatbin data */
125 #define FATBIN_PRELINK_DATA_SECTION_NAME "__nv_relfatbin"
127 #endif /* fatbinaryctl_INCLUDED */