MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / ggml_cl_init

Function ggml_cl_init

ggml-opencl.cpp:933–1148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

931}
932
933void ggml_cl_init(void) {
934 cl_int err;
935
936 struct cl_device;
937 struct cl_platform {
938 cl_platform_id id;
939 unsigned number;
940 char name[128];
941 char vendor[128];
942 struct cl_device * devices;
943 unsigned n_devices;
944 struct cl_device * default_device;
945 };
946
947 struct cl_device {
948 struct cl_platform * platform;
949 cl_device_id id;
950 unsigned number;
951 cl_device_type type;
952 char name[128];
953 };
954
955 enum { NPLAT = 16, NDEV = 16 };
956
957 struct cl_platform platforms[NPLAT];
958 unsigned n_platforms = 0;
959 struct cl_device devices[NDEV];
960 unsigned n_devices = 0;
961 struct cl_device * default_device = NULL;
962
963 platform = NULL;
964 device = NULL;
965
966 cl_platform_id platform_ids[NPLAT];
967 CL_CHECK(clGetPlatformIDs(NPLAT, platform_ids, &n_platforms));
968
969 for (unsigned i = 0; i < n_platforms; i++) {
970 struct cl_platform * p = &platforms[i];
971 p->number = i;
972 p->id = platform_ids[i];
973 CL_CHECK(clGetPlatformInfo(p->id, CL_PLATFORM_NAME, sizeof(p->name), &p->name, NULL));
974 CL_CHECK(clGetPlatformInfo(p->id, CL_PLATFORM_VENDOR, sizeof(p->vendor), &p->vendor, NULL));
975
976 cl_device_id device_ids[NDEV];
977 cl_int clGetDeviceIDsError = clGetDeviceIDs(p->id, CL_DEVICE_TYPE_ALL, NDEV, device_ids, &p->n_devices);
978 if (clGetDeviceIDsError == CL_DEVICE_NOT_FOUND) {
979 p->n_devices = 0;
980 } else {
981 CL_CHECK(clGetDeviceIDsError);
982 }
983 p->devices = p->n_devices > 0 ? &devices[n_devices] : NULL;
984 p->default_device = NULL;
985
986 for (unsigned j = 0; j < p->n_devices; j++) {
987 struct cl_device * d = &devices[n_devices];
988 d->number = n_devices++;
989 d->id = device_ids[j];
990 d->platform = p;

Callers 1

ggml_initFunction · 0.85

Calls 4

fprintfFunction · 0.85
generate_kernelsFunction · 0.85
c_strMethod · 0.45

Tested by

no test coverage detected