<commit_before>package cl11

import (
	"errors"
	"fmt"
	"strings"
	"unsafe"

	clw "github.com/rdwilliamson/clw11"
)

// Platforms implement specific features and allow applications to query
// devices.
type Platform struct {
	id clw.PlatformID

	// The profile name supported by the implementation, either the full profile
	// or a subset of each OpenCL version (embedded profile).
	Profile Profile

	// A Platform's version.
	Version Version

	// Platform's name.
	Name string

	// Vendor's name.
	Vendor string

	// Extensions supported by all devices associated with the platform.
	Extensions []string

	// Devices available on the platform.
	Devices []*Device
}

type Profile int

const (
	FullProfile     Profile = iota
	EmbeddedProfile Profile = iota
)

// Obtain the list of platforms available.
func GetPlatforms() ([]*Platform, error) {

	var numPlatforms clw.Uint
	err := clw.GetPlatformIDs(0, nil, &numPlatforms)
	if err != nil {
		return nil, err
	}

	platformIDs := make([]clw.PlatformID, numPlatforms)
	err = clw.GetPlatformIDs(numPlatforms, &platformIDs[0], nil)
	if err != nil {
		return nil, err
	}

	platforms := make([]*Platform, len(platformIDs))
	for i := range platforms {

		platforms[i] = &Platform{id: platformIDs[i]}

		err = platforms[i].getAllInfo()
		if err != nil {
			return nil, err
		}

		platforms[i].Devices, err = platforms[i].getDevices()
		if err != nil {
			return nil, err
		}
	}

	return platforms, nil
}

func (p *Platform) getAllInfo() (err error) {

	defer func() {
		if r := recover(); r != nil {
			err = r.(error)
		}
	}()

	p.Profile = toProfile(p.getString(clw.PlatformProfile))
	p.Version = toVersion(p.getString(clw.PlatformVersion))
	p.Name = p.getString(clw.PlatformName)
	p.Vendor = p.getString(clw.PlatformVendor)
	p.Extensions = strings.Split(p.getString(clw.PlatformExtensions), " ")

	return
}

func (p *Platform) getString(paramName clw.PlatformInfo) string {

	var paramValueSize clw.Size
	err := clw.GetPlatformInfo(p.id, paramName, 0, nil, &paramValueSize)
	if err != nil {
		panic(err)
	}

	buffer := make([]byte, paramValueSize)
	err = clw.GetPlatformInfo(p.id, paramName, paramValueSize, unsafe.Pointer(&buffer[0]), nil)
	if err != nil {
		panic(err)
	}

	// Trim space and trailing \0.
	return strings.TrimSpace(string(buffer[:len(buffer)-1]))
}

func toProfile(profile string) Profile {

	switch profile {
	case "FULL_PROFILE":
		return FullProfile
	case "EMBEDDED_PROFILE":
		return EmbeddedProfile
	}

	panic(errors.New("unknown profile"))
}

func (pp Profile) String() string {
	switch pp {
	case FullProfile:
		return "full profile"<commit_msg>Adding a zero value to profile.<commit_after>package cl11

import (
	"errors"
	"fmt"
	"strings"
	"unsafe"

	clw "github.com/rdwilliamson/clw11"
)

// Platforms implement specific features and allow applications to query
// devices.
type Platform struct {
	id clw.PlatformID

	// The profile name supported by the implementation, either the full profile
	// or a subset of each OpenCL version (embedded profile).
	Profile Profile

	// A Platform's version.
	Version Version

	// Platform's name.
	Name string

	// Vendor's name.
	Vendor string

	// Extensions supported by all devices associated with the platform.
	Extensions []string

	// Devices available on the platform.
	Devices []*Device
}

type Profile int

const (
	zeroProfile     Profile = iota
	FullProfile     Profile = iota
	EmbeddedProfile Profile = iota
)

// Obtain the list of platforms available.
func GetPlatforms() ([]*Platform, error) {

	var numPlatforms clw.Uint
	err := clw.GetPlatformIDs(0, nil, &numPlatforms)
	if err != nil {
		return nil, err
	}

	platformIDs := make([]clw.PlatformID, numPlatforms)
	err = clw.GetPlatformIDs(numPlatforms, &platformIDs[0], nil)
	if err != nil {
		return nil, err
	}

	platforms := make([]*Platform, len(platformIDs))
	for i := range platforms {

		platforms[i] = &Platform{id: platformIDs[i]}

		err = platforms[i].getAllInfo()
		if err != nil {
			return nil, err
		}

		platforms[i].Devices, err = platforms[i].getDevices()
		if err != nil {
			return nil, err
		}
	}

	return platforms, nil
}

func (p *Platform) getAllInfo() (err error) {

	defer func() {
		if r := recover(); r != nil {
			err = r.(error)
		}
	}()

	p.Profile = toProfile(p.getString(clw.PlatformProfile))
	p.Version = toVersion(p.getString(clw.PlatformVersion))
	p.Name = p.getString(clw.PlatformName)
	p.Vendor = p.getString(clw.PlatformVendor)
	p.Extensions = strings.Split(p.getString(clw.PlatformExtensions), " ")

	return
}

func (p *Platform) getString(paramName clw.PlatformInfo) string {

	var paramValueSize clw.Size
	err := clw.GetPlatformInfo(p.id, paramName, 0, nil, &paramValueSize)
	if err != nil {
		panic(err)
	}

	buffer := make([]byte, paramValueSize)
	err = clw.GetPlatformInfo(p.id, paramName, paramValueSize, unsafe.Pointer(&buffer[0]), nil)
	if err != nil {
		panic(err)
	}

	// Trim space and trailing \0.
	return strings.TrimSpace(string(buffer[:len(buffer)-1]))
}

func toProfile(profile string) Profile {

	switch profile {
	case "FULL_PROFILE":
		return FullProfile
	case "EMBEDDED_PROFILE":
		return EmbeddedProfile
	}

	panic(errors.New("unknown profile"))
}

func (pp Profile) String() string {
	switch pp {
	case zeroProfile:
		return ""
	case FullProfile:
		return "full profile"
{'fraction_non_alphanumeric': 0.12332893993598193, 'fraction_numerical': 0.003765769158350593, 'mean_word_length': 3.950605778191985, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2517471', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1770, 'n_words': 502}